signserver cleanup

This commit is contained in:
wish
2022-10-18 11:42:12 +11:00
parent c6c247b56b
commit 5e42402a3d
3 changed files with 17 additions and 38 deletions

View File

@@ -24,7 +24,6 @@ type Server struct {
sync.Mutex
logger *zap.Logger
erupeConfig *config.Config
sid int
sessions map[int]*Session
db *sqlx.DB
listener net.Listener
@@ -36,8 +35,6 @@ func NewServer(config *Config) *Server {
s := &Server{
logger: config.Logger,
erupeConfig: config.ErupeConfig,
sid: 0,
sessions: make(map[int]*Session),
db: config.DB,
}
return s
@@ -84,20 +81,19 @@ func (s *Server) acceptClients() {
}
}
go s.handleConnection(s.sid, conn)
s.sid++
go s.handleConnection(conn)
}
}
func (s *Server) handleConnection(sid int, conn net.Conn) {
func (s *Server) handleConnection(conn net.Conn) {
s.logger.Info("Got connection to sign server", zap.String("remoteaddr", conn.RemoteAddr().String()))
defer conn.Close()
// Client initalizes the connection with a one-time buffer of 8 NULL bytes.
nullInit := make([]byte, 8)
_, err := io.ReadFull(conn, nullInit)
if err != nil {
fmt.Println(err)
conn.Close()
s.logger.Error("Error initialising sign server connection", zap.Error(err))
return
}
@@ -105,15 +101,10 @@ func (s *Server) handleConnection(sid int, conn net.Conn) {
session := &Session{
logger: s.logger,
server: s,
rawConn: &conn,
rawConn: conn,
cryptConn: network.NewCryptConn(conn),
}
// Add the session to the server's sessions map.
s.Lock()
s.sessions[sid] = session
s.Unlock()
// Do the session's work.
session.work()
}