forked from External/grumble
Get rid of Server's SendUDP goroutine.
This commit is contained in:
parent
875cc89b9e
commit
03932c13cf
2 changed files with 31 additions and 40 deletions
34
client.go
34
client.go
|
|
@ -298,37 +298,41 @@ func (client *Client) udpreceiver() {
|
||||||
outgoing.PutBytes(buf[1 : 1+(len(buf)-1)])
|
outgoing.PutBytes(buf[1 : 1+(len(buf)-1)])
|
||||||
outbuf[0] = kind
|
outbuf[0] = kind
|
||||||
|
|
||||||
// VoiceTarget
|
if target != 0x1f { // VoiceTarget
|
||||||
if target != 0x1f {
|
|
||||||
client.server.voicebroadcast <- &VoiceBroadcast{
|
client.server.voicebroadcast <- &VoiceBroadcast{
|
||||||
client: client,
|
client: client,
|
||||||
buf: outbuf[0 : 1+outgoing.Size()],
|
buf: outbuf[0 : 1+outgoing.Size()],
|
||||||
target: target,
|
target: target,
|
||||||
}
|
}
|
||||||
// Server loopback
|
} else { // Server loopback
|
||||||
} else {
|
buf := outbuf[0 : 1+outgoing.Size()]
|
||||||
client.sendUdp(&Message{
|
err := client.SendUDP(buf)
|
||||||
buf: outbuf[0 : 1+outgoing.Size()],
|
if err != nil {
|
||||||
client: client,
|
client.Panicf("Unable to send UDP message: %v", err.Error())
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case mumbleproto.UDPMessagePing:
|
case mumbleproto.UDPMessagePing:
|
||||||
client.server.udpsend <- &Message{
|
err := client.SendUDP(buf)
|
||||||
buf: buf,
|
if err != nil {
|
||||||
client: client,
|
client.Panicf("Unable to send UDP message: %v", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) sendUdp(msg *Message) {
|
// Send buf as a UDP message. If the client does not have
|
||||||
|
// an established UDP connection, the datagram will be tunelled
|
||||||
|
// through the client's control channel (TCP).
|
||||||
|
func (client *Client) SendUDP(buf []byte) error {
|
||||||
if client.udp {
|
if client.udp {
|
||||||
client.Printf("Sent UDP!")
|
crypted := make([]byte, len(buf)+4)
|
||||||
client.server.udpsend <- msg
|
client.crypt.Encrypt(crypted, buf)
|
||||||
|
return client.server.SendUDP(crypted, client.udpaddr)
|
||||||
} else {
|
} else {
|
||||||
client.sendMessage(msg.buf)
|
return client.sendMessage(buf)
|
||||||
}
|
}
|
||||||
|
panic("unreachable")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send a Message to the client. The Message in msg to the client's
|
// Send a Message to the client. The Message in msg to the client's
|
||||||
|
|
|
||||||
37
server.go
37
server.go
|
|
@ -64,7 +64,6 @@ type Server struct {
|
||||||
running bool
|
running bool
|
||||||
|
|
||||||
incoming chan *Message
|
incoming chan *Message
|
||||||
udpsend chan *Message
|
|
||||||
voicebroadcast chan *VoiceBroadcast
|
voicebroadcast chan *VoiceBroadcast
|
||||||
cfgUpdate chan *KeyValuePair
|
cfgUpdate chan *KeyValuePair
|
||||||
|
|
||||||
|
|
@ -150,7 +149,6 @@ func NewServer(id int64, addr string, port int) (s *Server, err error) {
|
||||||
s.hpclients = make(map[string]*Client)
|
s.hpclients = make(map[string]*Client)
|
||||||
|
|
||||||
s.incoming = make(chan *Message)
|
s.incoming = make(chan *Message)
|
||||||
s.udpsend = make(chan *Message)
|
|
||||||
s.voicebroadcast = make(chan *VoiceBroadcast)
|
s.voicebroadcast = make(chan *VoiceBroadcast)
|
||||||
s.cfgUpdate = make(chan *KeyValuePair)
|
s.cfgUpdate = make(chan *KeyValuePair)
|
||||||
s.clientAuthenticated = make(chan *Client)
|
s.clientAuthenticated = make(chan *Client)
|
||||||
|
|
@ -362,10 +360,10 @@ func (server *Server) handler() {
|
||||||
channel := vb.client.Channel
|
channel := vb.client.Channel
|
||||||
for _, client := range channel.clients {
|
for _, client := range channel.clients {
|
||||||
if client != vb.client {
|
if client != vb.client {
|
||||||
client.sendUdp(&Message{
|
err := client.SendUDP(vb.buf)
|
||||||
buf: vb.buf,
|
if err != nil {
|
||||||
client: client,
|
client.Panic("Unable to send UDP: %v", err.Error())
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -878,21 +876,10 @@ func (s *Server) SetupUDP() (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) SendUDP() {
|
// Send the content of buf as a UDP packet to addr.
|
||||||
for {
|
func (s *Server) SendUDP(buf []byte, addr *net.UDPAddr) (err error) {
|
||||||
msg := <-s.udpsend
|
_, err = s.udpconn.WriteTo(buf, addr)
|
||||||
// Encrypted
|
return
|
||||||
if msg.client != nil {
|
|
||||||
crypted := make([]byte, len(msg.buf)+4)
|
|
||||||
msg.client.crypt.Encrypt(crypted, msg.buf)
|
|
||||||
s.udpconn.WriteTo(crypted, msg.client.udpaddr)
|
|
||||||
// Non-encrypted
|
|
||||||
} else if msg.address != nil {
|
|
||||||
s.udpconn.WriteTo(msg.buf, msg.address)
|
|
||||||
} else {
|
|
||||||
// Skipping
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listen for and handle UDP packets.
|
// Listen for and handle UDP packets.
|
||||||
|
|
@ -928,10 +915,11 @@ func (server *Server) ListenUDP() {
|
||||||
_ = binary.Write(buffer, binary.BigEndian, server.cfg.Uint32Value("MaxUsers"))
|
_ = binary.Write(buffer, binary.BigEndian, server.cfg.Uint32Value("MaxUsers"))
|
||||||
_ = binary.Write(buffer, binary.BigEndian, server.cfg.Uint32Value("MaxBandwidth"))
|
_ = binary.Write(buffer, binary.BigEndian, server.cfg.Uint32Value("MaxBandwidth"))
|
||||||
|
|
||||||
server.udpsend <- &Message{
|
err = server.SendUDP(buffer.Bytes(), udpaddr)
|
||||||
buf: buffer.Bytes(),
|
if err != nil {
|
||||||
address: udpaddr,
|
server.Print("Unable to write UDP packet: %v", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
server.handleUdpPacket(udpaddr, buf, nread)
|
server.handleUdpPacket(udpaddr, buf, nread)
|
||||||
}
|
}
|
||||||
|
|
@ -1183,7 +1171,6 @@ func (s *Server) ListenAndMurmur() {
|
||||||
// Setup our UDP listener and spawn our reader and writer goroutines
|
// Setup our UDP listener and spawn our reader and writer goroutines
|
||||||
s.SetupUDP()
|
s.SetupUDP()
|
||||||
go s.ListenUDP()
|
go s.ListenUDP()
|
||||||
go s.SendUDP()
|
|
||||||
|
|
||||||
// Create a new listening TLS socket.
|
// Create a new listening TLS socket.
|
||||||
certFn := filepath.Join(Args.DataDir, "cert.pem")
|
certFn := filepath.Join(Args.DataDir, "cert.pem")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue