diff --git a/server.go b/server.go index d4cbf7c..dbec47a 100644 --- a/server.go +++ b/server.go @@ -119,6 +119,13 @@ func runServer(s *server) { func handleServerConnection(s *server, conn io.ReadWriteCloser, clientAddr string) { defer s.stopWg.Done() + + if err := s.serverHandler.OnHandshake(clientAddr, conn); nil != err { + logging.Logger.Error(fmt.Sprintf("Server: [%s]. handshake error: [%s]", clientAddr, err)) + conn.Close() + return + } + logging.Logger.Debug(fmt.Sprintf("Server: Client[%s] is connected.", clientAddr)) clientStopChan := make(chan struct{}) go s.serverHandler.Handle(clientAddr, conn, clientStopChan) diff --git a/server_handler.go b/server_handler.go index 59750cd..a1d1e4d 100644 --- a/server_handler.go +++ b/server_handler.go @@ -7,6 +7,7 @@ import ( type ServerHandler interface { Listen() (net.Listener, error) + OnHandshake(remoteAddr string, rwc io.ReadWriteCloser) error Handle(remoteAddr string, rwc io.ReadWriteCloser, stopChan chan struct{}) OnStopped() diff --git a/server_handlers.go b/server_handlers.go index 1d33a4a..974a945 100644 --- a/server_handlers.go +++ b/server_handlers.go @@ -27,6 +27,10 @@ func (sh *ServerHandlers) Listen() (net.Listener, error) { return nil, errors.New("Server: Handler method[Listen] of Server is not implement") } +func (sh *ServerHandlers) OnHandshake(remoteAddr string, rwc io.ReadWriteCloser) error { + return nil +} + func (sh *ServerHandlers) Handle(remoteAddr string, rwc io.ReadWriteCloser, stopChan chan struct{}) { }