ClientConnection -> Client.

This commit is contained in:
Mikkel Krautz 2010-11-07 23:05:30 +01:00
parent aa3f0add53
commit 122b6af163
3 changed files with 33 additions and 33 deletions

View file

@ -17,7 +17,7 @@ import (
) )
// A client connection // A client connection
type ClientConnection struct { type Client struct {
// Connection-related // Connection-related
tcpaddr *net.TCPAddr tcpaddr *net.TCPAddr
udpaddr *net.UDPAddr udpaddr *net.UDPAddr
@ -43,14 +43,14 @@ type ClientConnection struct {
} }
// Something invalid happened on the wire. // Something invalid happened on the wire.
func (client *ClientConnection) Panic(reason string) { func (client *Client) Panic(reason string) {
client.disconnected = true client.disconnected = true
// fixme(mkrautz): we should inform the server "handler" method through a channel of this event, // fixme(mkrautz): we should inform the server "handler" method through a channel of this event,
// so it can perform a proper disconnect. // so it can perform a proper disconnect.
} }
// Read a protobuf message from a client // Read a protobuf message from a client
func (client *ClientConnection) readProtoMessage() (msg *Message, err os.Error) { func (client *Client) readProtoMessage() (msg *Message, err os.Error) {
var length uint32 var length uint32
var kind uint16 var kind uint16
@ -85,7 +85,7 @@ func (client *ClientConnection) readProtoMessage() (msg *Message, err os.Error)
} }
// Send a protobuf-encoded message // Send a protobuf-encoded message
func (c *ClientConnection) sendProtoMessage(kind uint16, msg interface{}) (err os.Error) { func (c *Client) sendProtoMessage(kind uint16, msg interface{}) (err os.Error) {
d, err := proto.Marshal(msg) d, err := proto.Marshal(msg)
if err != nil { if err != nil {
return return
@ -100,7 +100,7 @@ func (c *ClientConnection) sendProtoMessage(kind uint16, msg interface{}) (err o
} }
// UDP receiver. // UDP receiver.
func (client *ClientConnection) udpreceiver() { func (client *Client) udpreceiver() {
for { for {
buf := <-client.udprecv buf := <-client.udprecv
kind := (buf[0] >> 5) & 0x07; kind := (buf[0] >> 5) & 0x07;
@ -146,7 +146,7 @@ func (client *ClientConnection) udpreceiver() {
} }
} }
func (client *ClientConnection) sendUdp(msg *Message) { func (client *Client) sendUdp(msg *Message) {
if client.udp { if client.udp {
log.Printf("Sent UDP!") log.Printf("Sent UDP!")
client.server.udpsend <- msg client.server.udpsend <- msg
@ -161,7 +161,7 @@ func (client *ClientConnection) sendUdp(msg *Message) {
// //
// Sender Goroutine // Sender Goroutine
// //
func (client *ClientConnection) sender() { func (client *Client) sender() {
for { for {
msg := <-client.msgchan msg := <-client.msgchan
@ -196,7 +196,7 @@ func (client *ClientConnection) sender() {
} }
// Receiver Goroutine // Receiver Goroutine
func (client *ClientConnection) receiver() { func (client *Client) receiver() {
for { for {
// The version handshake is done. Forward this message to the synchronous request handler. // The version handshake is done. Forward this message to the synchronous request handler.
@ -249,7 +249,7 @@ func (client *ClientConnection) receiver() {
} }
// Send the channel list to a client. // Send the channel list to a client.
func (client *ClientConnection) sendChannelList() { func (client *Client) sendChannelList() {
server := client.server server := client.server
root := server.root root := server.root
@ -266,7 +266,7 @@ func (client *ClientConnection) sendChannelList() {
} }
// Send the userlist to a client. // Send the userlist to a client.
func (client *ClientConnection) sendUserList() { func (client *Client) sendUserList() {
server := client.server server := client.server
server.cmutex.RLock() server.cmutex.RLock()

View file

@ -61,11 +61,11 @@ 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 *ClientConnection client *Client
address net.Addr address net.Addr
} }
func (server *Server) handleCryptSetup(client *ClientConnection, msg *Message) { func (server *Server) handleCryptSetup(client *Client, msg *Message) {
cs := &mumbleproto.CryptSetup{} cs := &mumbleproto.CryptSetup{}
err := proto.Unmarshal(msg.buf, cs) err := proto.Unmarshal(msg.buf, cs)
if err != nil { if err != nil {
@ -96,7 +96,7 @@ func (server *Server) handleCryptSetup(client *ClientConnection, msg *Message) {
} }
} }
func (server *Server) handlePingMessage(client *ClientConnection, msg *Message) { func (server *Server) handlePingMessage(client *Client, msg *Message) {
ping := &mumbleproto.Ping{} ping := &mumbleproto.Ping{}
err := proto.Unmarshal(msg.buf, ping) err := proto.Unmarshal(msg.buf, ping)
if err != nil { if err != nil {
@ -115,25 +115,25 @@ func (server *Server) handlePingMessage(client *ClientConnection, msg *Message)
}) })
} }
func (server *Server) handleChannelAddMessage(client *ClientConnection, msg *Message) { func (server *Server) handleChannelAddMessage(client *Client, msg *Message) {
} }
func (server *Server) handleChannelRemoveMessage(client *ClientConnection, msg *Message) { func (server *Server) handleChannelRemoveMessage(client *Client, msg *Message) {
} }
func (server *Server) handleChannelStateMessage(client *ClientConnection, msg *Message) { func (server *Server) handleChannelStateMessage(client *Client, msg *Message) {
} }
func (server *Server) handleUserRemoveMessage(client *ClientConnection, msg *Message) { func (server *Server) handleUserRemoveMessage(client *Client, msg *Message) {
} }
func (server *Server) handleUserStateMessage(client *ClientConnection, msg *Message) { func (server *Server) handleUserStateMessage(client *Client, msg *Message) {
} }
func (server *Server) handleBanListMessage(client *ClientConnection, msg *Message) { func (server *Server) handleBanListMessage(client *Client, msg *Message) {
} }
func (server *Server) handleTextMessage(client *ClientConnection, msg *Message) { func (server *Server) handleTextMessage(client *Client, msg *Message) {
txtmsg := &mumbleproto.TextMessage{} txtmsg := &mumbleproto.TextMessage{}
err := proto.Unmarshal(msg.buf, txtmsg) err := proto.Unmarshal(msg.buf, txtmsg)
if err != nil { if err != nil {
@ -141,9 +141,9 @@ func (server *Server) handleTextMessage(client *ClientConnection, msg *Message)
return return
} }
users := []*ClientConnection{}; users := []*Client{};
for i := 0; i < len(txtmsg.Session); i++ { for i := 0; i < len(txtmsg.Session); i++ {
user := server.getClientConnection(txtmsg.Session[i]) user := server.getClient(txtmsg.Session[i])
users = append(users, user) users = append(users, user)
} }
@ -155,16 +155,16 @@ func (server *Server) handleTextMessage(client *ClientConnection, msg *Message)
} }
} }
func (server *Server) handleAclMessage(client *ClientConnection, msg *Message) { func (server *Server) handleAclMessage(client *Client, msg *Message) {
} }
// User query // User query
func (server *Server) handleQueryUsers(client *ClientConnection, msg *Message) { func (server *Server) handleQueryUsers(client *Client, msg *Message) {
} }
// User stats message. Shown in the Mumble client when a // User stats message. Shown in the Mumble client when a
// user right clicks a user and selects 'User Information'. // user right clicks a user and selects 'User Information'.
func (server *Server) handleUserStatsMessage(client *ClientConnection, msg *Message) { func (server *Server) handleUserStatsMessage(client *Client, msg *Message) {
stats := &mumbleproto.UserStats{} stats := &mumbleproto.UserStats{}
err := proto.Unmarshal(msg.buf, stats) err := proto.Unmarshal(msg.buf, stats)
if err != nil { if err != nil {

View file

@ -54,7 +54,7 @@ type Server struct {
// A list of all connected clients // A list of all connected clients
cmutex *sync.RWMutex cmutex *sync.RWMutex
clients []*ClientConnection clients []*Client
// Codec information // Codec information
AlphaCodec int32 AlphaCodec int32
@ -106,7 +106,7 @@ func NewServer(addr string, port int) (s *Server, err os.Error) {
// Called by the server to initiate a new client connection. // Called by the server to initiate a new client connection.
func (server *Server) NewClient(conn net.Conn) (err os.Error) { func (server *Server) NewClient(conn net.Conn) (err os.Error) {
client := new(ClientConnection) client := new(Client)
// Get the address of the connected client // Get the address of the connected client
if addr := conn.RemoteAddr(); addr != nil { if addr := conn.RemoteAddr(); addr != nil {
@ -140,7 +140,7 @@ func (server *Server) NewClient(conn net.Conn) (err os.Error) {
} }
// Lookup a client by it's session id. Optimize this by using a map. // Lookup a client by it's session id. Optimize this by using a map.
func (server *Server) getClientConnection(session uint32) (client *ClientConnection) { func (server *Server) getClient(session uint32) (client *Client) {
server.cmutex.RLock() server.cmutex.RLock()
defer server.cmutex.RUnlock() defer server.cmutex.RUnlock()
@ -167,7 +167,7 @@ func (server *Server) handler() {
} }
} }
func (server *Server) handleAuthenticate(client *ClientConnection, msg *Message) { func (server *Server) handleAuthenticate(client *Client, msg *Message) {
// Is this message not an authenticate message? If not, discard it... // Is this message not an authenticate message? If not, discard it...
if msg.kind != MessageAuthenticate { if msg.kind != MessageAuthenticate {
client.Panic("Unexpected message. Expected Authenticate.") client.Panic("Unexpected message. Expected Authenticate.")
@ -313,7 +313,7 @@ func (server *Server) updateCodecVersions() {
return return
} }
func (server *Server) sendUserList(client *ClientConnection) { func (server *Server) sendUserList(client *Client) {
server.cmutex.RLock() server.cmutex.RLock()
defer server.cmutex.RUnlock() defer server.cmutex.RUnlock()
@ -355,7 +355,7 @@ func (server *Server) broadcastProtoMessage(kind uint16, msg interface{}) (err o
return return
} }
func (server *Server) handleIncomingMessage(client *ClientConnection, msg *Message) { func (server *Server) handleIncomingMessage(client *Client, msg *Message) {
log.Printf("Handle Incoming Message") log.Printf("Handle Incoming Message")
switch msg.kind { switch msg.kind {
case MessagePing: case MessagePing:
@ -474,7 +474,7 @@ func (server *Server) ListenUDP() {
address: udpaddr, address: udpaddr,
} }
} else { } else {
var match *ClientConnection var match *Client
plain := make([]byte, nread-4) plain := make([]byte, nread-4)
decrypted := false decrypted := false
@ -502,7 +502,7 @@ func (server *Server) ListenUDP() {
decrypted = true decrypted = true
// If we were able to successfully decrpyt, add // If we were able to successfully decrpyt, add
// the UDPAddr to the ClientConnection struct. // the UDPAddr to the Client struct.
log.Printf("Client UDP connection established.") log.Printf("Client UDP connection established.")
client.udpaddr = remote.(*net.UDPAddr) client.udpaddr = remote.(*net.UDPAddr)
match = client match = client