Refactor: make IntermediateConnection more like Connection

This commit is contained in:
Jakob Borg 2015-08-23 08:55:32 +02:00
parent f691040936
commit aec143b882
2 changed files with 7 additions and 9 deletions

View File

@ -143,7 +143,7 @@ next:
s.mut.RLock() s.mut.RLock()
ct, ok := s.connType[remoteID] ct, ok := s.connType[remoteID]
s.mut.RUnlock() s.mut.RUnlock()
if ok && !ct.IsDirect() && c.ConnType.IsDirect() { if ok && !ct.IsDirect() && c.Type.IsDirect() {
if debugNet { if debugNet {
l.Debugln("Switching connections", remoteID) l.Debugln("Switching connections", remoteID)
} }
@ -194,7 +194,7 @@ next:
rd = &limitedReader{c.Conn, readRateLimit} rd = &limitedReader{c.Conn, readRateLimit}
} }
name := fmt.Sprintf("%s-%s (%s)", c.Conn.LocalAddr(), c.Conn.RemoteAddr(), c.ConnType) name := fmt.Sprintf("%s-%s (%s)", c.Conn.LocalAddr(), c.Conn.RemoteAddr(), c.Type)
protoConn := protocol.NewConnection(remoteID, rd, wr, s.model, name, deviceCfg.Compression) protoConn := protocol.NewConnection(remoteID, rd, wr, s.model, name, deviceCfg.Compression)
l.Infof("Established secure connection to %s at %s", remoteID, name) l.Infof("Established secure connection to %s at %s", remoteID, name)
@ -205,10 +205,10 @@ next:
s.model.AddConnection(model.Connection{ s.model.AddConnection(model.Connection{
c.Conn, c.Conn,
protoConn, protoConn,
c.ConnType, c.Type,
}) })
s.mut.Lock() s.mut.Lock()
s.connType[remoteID] = c.ConnType s.connType[remoteID] = c.Type
s.mut.Unlock() s.mut.Unlock()
continue next continue next
} }
@ -219,11 +219,9 @@ next:
"device": remoteID.String(), "device": remoteID.String(),
"address": c.Conn.RemoteAddr().String(), "address": c.Conn.RemoteAddr().String(),
}) })
l.Infof("Connection from %s (%s) with unknown device ID %s", c.Conn.RemoteAddr(), c.ConnType, remoteID)
} else {
l.Infof("Connection from %s (%s) with ignored device ID %s", c.Conn.RemoteAddr(), c.ConnType, remoteID)
} }
l.Infof("Connection from %s (%s) with ignored device ID %s", c.Conn.RemoteAddr(), c.Type, remoteID)
c.Conn.Close() c.Conn.Close()
} }
} }

View File

@ -14,8 +14,8 @@ import (
) )
type IntermediateConnection struct { type IntermediateConnection struct {
Conn *tls.Conn *tls.Conn
ConnType ConnectionType Type ConnectionType
} }
type Connection struct { type Connection struct {