mirror of
https://github.com/mumble-voip/grumble.git
synced 2025-12-20 06:10:00 -08:00
gofmt run.
This commit is contained in:
parent
a57908b487
commit
c2f3f0de47
3 changed files with 55 additions and 54 deletions
51
client.go
51
client.go
|
|
@ -19,8 +19,8 @@ import (
|
||||||
// A client connection
|
// A client connection
|
||||||
type Client struct {
|
type Client struct {
|
||||||
// Connection-related
|
// Connection-related
|
||||||
tcpaddr *net.TCPAddr
|
tcpaddr *net.TCPAddr
|
||||||
udpaddr *net.UDPAddr
|
udpaddr *net.UDPAddr
|
||||||
conn net.Conn
|
conn net.Conn
|
||||||
reader *bufio.Reader
|
reader *bufio.Reader
|
||||||
writer *bufio.Writer
|
writer *bufio.Writer
|
||||||
|
|
@ -32,9 +32,9 @@ type Client struct {
|
||||||
|
|
||||||
disconnected bool
|
disconnected bool
|
||||||
|
|
||||||
crypt *cryptstate.CryptState
|
crypt *cryptstate.CryptState
|
||||||
codecs []int32
|
codecs []int32
|
||||||
udp bool
|
udp bool
|
||||||
|
|
||||||
// Personal
|
// Personal
|
||||||
Session uint32
|
Session uint32
|
||||||
|
|
@ -82,8 +82,8 @@ func (client *Client) readProtoMessage() (msg *Message, err os.Error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
msg = &Message{
|
msg = &Message{
|
||||||
buf: buf,
|
buf: buf,
|
||||||
kind: kind,
|
kind: kind,
|
||||||
client: client,
|
client: client,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,44 +114,46 @@ func (client *Client) udpreceiver() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
kind := (buf[0] >> 5) & 0x07;
|
kind := (buf[0] >> 5) & 0x07
|
||||||
|
|
||||||
switch kind {
|
switch kind {
|
||||||
case UDPMessageVoiceSpeex: fallthrough;
|
case UDPMessageVoiceSpeex:
|
||||||
case UDPMessageVoiceCELTAlpha: fallthrough;
|
fallthrough
|
||||||
|
case UDPMessageVoiceCELTAlpha:
|
||||||
|
fallthrough
|
||||||
case UDPMessageVoiceCELTBeta:
|
case UDPMessageVoiceCELTBeta:
|
||||||
kind := buf[0] & 0xe0
|
kind := buf[0] & 0xe0
|
||||||
target := buf[0] & 0x1f
|
target := buf[0] & 0x1f
|
||||||
var counter uint8
|
var counter uint8
|
||||||
outbuf := make([]byte, 1024)
|
outbuf := make([]byte, 1024)
|
||||||
|
|
||||||
incoming := packetdatastream.New(buf[1:1+(len(buf)-1)])
|
incoming := packetdatastream.New(buf[1 : 1+(len(buf)-1)])
|
||||||
outgoing := packetdatastream.New(outbuf[1:1+(len(outbuf)-1)])
|
outgoing := packetdatastream.New(outbuf[1 : 1+(len(outbuf)-1)])
|
||||||
_ = incoming.GetUint32()
|
_ = incoming.GetUint32()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
counter = incoming.Next8()
|
counter = incoming.Next8()
|
||||||
incoming.Skip(int(counter & 0x7f))
|
incoming.Skip(int(counter & 0x7f))
|
||||||
if !((counter & 0x80) != 0 && incoming.IsValid()) {
|
if !((counter&0x80) != 0 && incoming.IsValid()) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
outgoing.PutUint32(client.Session)
|
outgoing.PutUint32(client.Session)
|
||||||
outgoing.PutBytes(buf[1:1+(len(buf)-1)])
|
outgoing.PutBytes(buf[1 : 1+(len(buf)-1)])
|
||||||
|
|
||||||
// Sever loopback
|
// Sever loopback
|
||||||
if target == 0x1f {
|
if target == 0x1f {
|
||||||
outbuf[0] = kind
|
outbuf[0] = kind
|
||||||
client.sendUdp(&Message{
|
client.sendUdp(&Message{
|
||||||
buf: outbuf[0:1+outgoing.Size()],
|
buf: outbuf[0 : 1+outgoing.Size()],
|
||||||
client: client,
|
client: client,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
case UDPMessagePing:
|
case UDPMessagePing:
|
||||||
client.server.udpsend <- &Message{
|
client.server.udpsend <- &Message{
|
||||||
buf: buf,
|
buf: buf,
|
||||||
client: client,
|
client: client,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -240,8 +242,8 @@ func (client *Client) receiver() {
|
||||||
// what version of the protocol it should speak.
|
// what version of the protocol it should speak.
|
||||||
if client.state == StateClientConnected {
|
if client.state == StateClientConnected {
|
||||||
client.sendProtoMessage(MessageVersion, &mumbleproto.Version{
|
client.sendProtoMessage(MessageVersion, &mumbleproto.Version{
|
||||||
Version: proto.Uint32(0x10203),
|
Version: proto.Uint32(0x10203),
|
||||||
Release: proto.String("1.2.2"),
|
Release: proto.String("1.2.2"),
|
||||||
})
|
})
|
||||||
// fixme(mkrautz): Re-add OS information... Does it break anything? It seems like
|
// fixme(mkrautz): Re-add OS information... Does it break anything? It seems like
|
||||||
// the client discards the version message if there is no OS information in it.
|
// the client discards the version message if there is no OS information in it.
|
||||||
|
|
@ -280,8 +282,8 @@ func (client *Client) sendChannelList() {
|
||||||
|
|
||||||
// Start at the root channel.
|
// Start at the root channel.
|
||||||
err := client.sendProtoMessage(MessageChannelState, &mumbleproto.ChannelState{
|
err := client.sendProtoMessage(MessageChannelState, &mumbleproto.ChannelState{
|
||||||
ChannelId: proto.Uint32(uint32(root.Id)),
|
ChannelId: proto.Uint32(uint32(root.Id)),
|
||||||
Name: proto.String(root.Name),
|
Name: proto.String(root.Name),
|
||||||
Description: proto.String(root.Description),
|
Description: proto.String(root.Description),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -295,8 +297,8 @@ func (client *Client) sendUserList() {
|
||||||
server := client.server
|
server := client.server
|
||||||
for _, client := range server.clients {
|
for _, client := range server.clients {
|
||||||
err := client.sendProtoMessage(MessageUserState, &mumbleproto.UserState{
|
err := client.sendProtoMessage(MessageUserState, &mumbleproto.UserState{
|
||||||
Session: proto.Uint32(client.Session),
|
Session: proto.Uint32(client.Session),
|
||||||
Name: proto.String(client.Username),
|
Name: proto.String(client.Username),
|
||||||
ChannelId: proto.Uint32(0),
|
ChannelId: proto.Uint32(0),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -305,4 +307,3 @@ func (client *Client) sendUserList() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Message struct {
|
type Message struct {
|
||||||
buf []byte
|
buf []byte
|
||||||
|
|
||||||
// Kind denotes a message kind for TCP packets. This field
|
// Kind denotes a message kind for TCP packets. This field
|
||||||
// is ignored for UDP packets.
|
// is ignored for UDP packets.
|
||||||
|
|
@ -61,7 +61,7 @@ type Message struct {
|
||||||
// If there is no connection established, address must be used.
|
// If there is no connection established, address must be used.
|
||||||
// If the datagram comes from an already-connected client, the
|
// If the datagram comes from an already-connected client, the
|
||||||
// client field should point to that client.
|
// client field should point to that client.
|
||||||
client *Client
|
client *Client
|
||||||
address net.Addr
|
address net.Addr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -141,7 +141,7 @@ func (server *Server) handleTextMessage(client *Client, msg *Message) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
users := []*Client{};
|
users := []*Client{}
|
||||||
for i := 0; i < len(txtmsg.Session); i++ {
|
for i := 0; i < len(txtmsg.Session); i++ {
|
||||||
user, ok := server.clients[txtmsg.Session[i]]
|
user, ok := server.clients[txtmsg.Session[i]]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
|
||||||
52
server.go
52
server.go
|
|
@ -20,10 +20,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// The default port a Murmur server listens on
|
// The default port a Murmur server listens on
|
||||||
const DefaultPort = 64738
|
const DefaultPort = 64738
|
||||||
const UDPPacketSize = 1024
|
const UDPPacketSize = 1024
|
||||||
|
|
||||||
const CeltCompatBitstream = -2147483638
|
const CeltCompatBitstream = -2147483638
|
||||||
|
|
||||||
// Client connection states
|
// Client connection states
|
||||||
const (
|
const (
|
||||||
|
|
@ -43,23 +43,23 @@ type Server struct {
|
||||||
|
|
||||||
incoming chan *Message
|
incoming chan *Message
|
||||||
outgoing chan *Message
|
outgoing chan *Message
|
||||||
udpsend chan *Message
|
udpsend chan *Message
|
||||||
|
|
||||||
// Config-related
|
// Config-related
|
||||||
MaxUsers int
|
MaxUsers int
|
||||||
MaxBandwidth uint32
|
MaxBandwidth uint32
|
||||||
|
|
||||||
// Clients
|
// Clients
|
||||||
session uint32
|
session uint32
|
||||||
clients map[uint32]*Client
|
clients map[uint32]*Client
|
||||||
|
|
||||||
hmutex *sync.RWMutex
|
hmutex *sync.RWMutex
|
||||||
hclients map[string][]*Client
|
hclients map[string][]*Client
|
||||||
hpclients map[string]*Client
|
hpclients map[string]*Client
|
||||||
|
|
||||||
// Codec information
|
// Codec information
|
||||||
AlphaCodec int32
|
AlphaCodec int32
|
||||||
BetaCodec int32
|
BetaCodec int32
|
||||||
PreferAlphaCodec bool
|
PreferAlphaCodec bool
|
||||||
|
|
||||||
root *Channel
|
root *Channel
|
||||||
|
|
@ -67,12 +67,12 @@ type Server struct {
|
||||||
|
|
||||||
// A Mumble channel
|
// A Mumble channel
|
||||||
type Channel struct {
|
type Channel struct {
|
||||||
Id int
|
Id int
|
||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
Temporary bool
|
Temporary bool
|
||||||
Position int
|
Position int
|
||||||
Channels *list.List
|
Channels *list.List
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate a new Murmur instance
|
// Allocate a new Murmur instance
|
||||||
|
|
@ -96,7 +96,7 @@ func NewServer(addr string, port int) (s *Server, err os.Error) {
|
||||||
s.MaxUsers = 10
|
s.MaxUsers = 10
|
||||||
|
|
||||||
s.root = &Channel{
|
s.root = &Channel{
|
||||||
Id: 0,
|
Id: 0,
|
||||||
Name: "Root",
|
Name: "Root",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -186,7 +186,7 @@ func (server *Server) handleAuthenticate(client *Client, msg *Message) {
|
||||||
// Send CryptState information to the client so it can establish an UDP connection,
|
// Send CryptState information to the client so it can establish an UDP connection,
|
||||||
// if it wishes.
|
// if it wishes.
|
||||||
err = client.sendProtoMessage(MessageCryptSetup, &mumbleproto.CryptSetup{
|
err = client.sendProtoMessage(MessageCryptSetup, &mumbleproto.CryptSetup{
|
||||||
Key: client.crypt.RawKey[0:],
|
Key: client.crypt.RawKey[0:],
|
||||||
ClientNonce: client.crypt.DecryptIV[0:],
|
ClientNonce: client.crypt.DecryptIV[0:],
|
||||||
ServerNonce: client.crypt.EncryptIV[0:],
|
ServerNonce: client.crypt.EncryptIV[0:],
|
||||||
})
|
})
|
||||||
|
|
@ -214,9 +214,9 @@ func (server *Server) handleAuthenticate(client *Client, msg *Message) {
|
||||||
|
|
||||||
// Broadcast the the user entered a channel
|
// Broadcast the the user entered a channel
|
||||||
err = server.broadcastProtoMessage(MessageUserState, &mumbleproto.UserState{
|
err = server.broadcastProtoMessage(MessageUserState, &mumbleproto.UserState{
|
||||||
Session: proto.Uint32(client.Session),
|
Session: proto.Uint32(client.Session),
|
||||||
Name: proto.String(client.Username),
|
Name: proto.String(client.Username),
|
||||||
ChannelId: proto.Uint32(0),
|
ChannelId: proto.Uint32(0),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
client.Panic(err.String())
|
client.Panic(err.String())
|
||||||
|
|
@ -225,8 +225,8 @@ func (server *Server) handleAuthenticate(client *Client, msg *Message) {
|
||||||
server.sendUserList(client)
|
server.sendUserList(client)
|
||||||
|
|
||||||
err = client.sendProtoMessage(MessageServerSync, &mumbleproto.ServerSync{
|
err = client.sendProtoMessage(MessageServerSync, &mumbleproto.ServerSync{
|
||||||
Session: proto.Uint32(client.Session),
|
Session: proto.Uint32(client.Session),
|
||||||
MaxBandwidth: proto.Uint32(server.MaxBandwidth),
|
MaxBandwidth: proto.Uint32(server.MaxBandwidth),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
client.Panic(err.String())
|
client.Panic(err.String())
|
||||||
|
|
@ -234,8 +234,8 @@ func (server *Server) handleAuthenticate(client *Client, msg *Message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
err = client.sendProtoMessage(MessageServerConfig, &mumbleproto.ServerConfig{
|
err = client.sendProtoMessage(MessageServerConfig, &mumbleproto.ServerConfig{
|
||||||
AllowHtml: proto.Bool(true),
|
AllowHtml: proto.Bool(true),
|
||||||
MessageLength: proto.Uint32(1000),
|
MessageLength: proto.Uint32(1000),
|
||||||
ImageMessageLength: proto.Uint32(1000),
|
ImageMessageLength: proto.Uint32(1000),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -282,7 +282,7 @@ func (server *Server) updateCodecVersions() {
|
||||||
server.PreferAlphaCodec = !server.PreferAlphaCodec
|
server.PreferAlphaCodec = !server.PreferAlphaCodec
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server.PreferAlphaCodec) {
|
if server.PreferAlphaCodec {
|
||||||
server.AlphaCodec = winner
|
server.AlphaCodec = winner
|
||||||
} else {
|
} else {
|
||||||
server.BetaCodec = winner
|
server.BetaCodec = winner
|
||||||
|
|
@ -330,7 +330,7 @@ func (server *Server) broadcastProtoMessage(kind uint16, msg interface{}) (err o
|
||||||
if client.state != StateClientAuthenticated {
|
if client.state != StateClientAuthenticated {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
err :=client.sendProtoMessage(kind, msg)
|
err := client.sendProtoMessage(kind, msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -454,7 +454,7 @@ func (server *Server) ListenUDP() {
|
||||||
_ = binary.Write(buffer, binary.BigEndian, uint32(server.MaxBandwidth))
|
_ = binary.Write(buffer, binary.BigEndian, uint32(server.MaxBandwidth))
|
||||||
|
|
||||||
server.udpsend <- &Message{
|
server.udpsend <- &Message{
|
||||||
buf: buffer.Bytes(),
|
buf: buffer.Bytes(),
|
||||||
address: udpaddr,
|
address: udpaddr,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue