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()
ct, ok := s.connType[remoteID]
s.mut.RUnlock()
if ok && !ct.IsDirect() && c.ConnType.IsDirect() {
if ok && !ct.IsDirect() && c.Type.IsDirect() {
if debugNet {
l.Debugln("Switching connections", remoteID)
}
@ -194,7 +194,7 @@ next:
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)
l.Infof("Established secure connection to %s at %s", remoteID, name)
@ -205,10 +205,10 @@ next:
s.model.AddConnection(model.Connection{
c.Conn,
protoConn,
c.ConnType,
c.Type,
})
s.mut.Lock()
s.connType[remoteID] = c.ConnType
s.connType[remoteID] = c.Type
s.mut.Unlock()
continue next
}
@ -219,11 +219,9 @@ next:
"device": remoteID.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()
}
}

View File

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