server: do not allow a client to control a session created with a different IP

This commit is contained in:
aler9
2021-09-23 19:52:57 +02:00
parent 0454e5407f
commit 239b71d975
9 changed files with 42 additions and 41 deletions

View File

@@ -47,6 +47,7 @@ type ServerConn struct {
ctx context.Context
ctxCancel func()
remoteAddr *net.TCPAddr // to improve speed
br *bufio.Reader
bw *bufio.Writer
sessions map[string]*ServerSession
@@ -76,6 +77,7 @@ func newServerConn(
nconn: nconn,
ctx: ctx,
ctxCancel: ctxCancel,
remoteAddr: nconn.RemoteAddr().(*net.TCPAddr),
sessionRemove: make(chan *ServerSession),
done: make(chan struct{}),
}
@@ -98,11 +100,11 @@ func (sc *ServerConn) NetConn() net.Conn {
}
func (sc *ServerConn) ip() net.IP {
return sc.nconn.RemoteAddr().(*net.TCPAddr).IP
return sc.remoteAddr.IP
}
func (sc *ServerConn) zone() string {
return sc.nconn.RemoteAddr().(*net.TCPAddr).Zone
return sc.remoteAddr.Zone
}
func (sc *ServerConn) run() {