From 141fffa204bbbec79a9cd82b4da3303a7b97ea41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bires?= Date: Thu, 17 Mar 2022 17:02:43 -0300 Subject: [PATCH] Added established and finished handlers to server --- server.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/server.go b/server.go index 2b891ff..7f34512 100644 --- a/server.go +++ b/server.go @@ -125,6 +125,11 @@ func (srv *Server) handleChannel(ctx context.Context, c *ServerChannel) { return } + established := srv.config.Established + if established != nil { + established(ctx, c.remoteNode, c.sessionID) + } + defer func() { if c.Established() { // Do not use the shared context since it could be canceled @@ -132,6 +137,11 @@ func (srv *Server) handleChannel(ctx context.Context, c *ServerChannel) { defer cancel() _ = c.FinishSession(ctx) } + + finished := srv.config.Finished + if finished != nil { + finished(context.Background(), c.remoteNode) + } }() if err = srv.mux.ListenServer(ctx, c); err != nil { @@ -176,6 +186,10 @@ type ServerConfig struct { Authenticate func(context.Context, Identity, Authentication) (*AuthenticationResult, error) // Register is called for the client Node address registration. Register func(context.Context, Node, *ServerChannel) (Node, error) + // Established is called when a session with a node is established. + Established func(ctx context.Context, n Node, sessionID string) + // Finished is called when an established session with a node is finished. + Finished func(context.Context, Node) } var defaultServerConfig = NewServerConfig()