You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

59 lines
1.7 KiB

package tunnel
import (
"context"
"gitlab.com/wpetit/goweb/logger"
)
type OnClientAuthFunc func(ctx context.Context, remoteClient *RemoteClient, credentials interface{}) (bool, error)
type OnClientAuthHook interface {
OnClientAuth(ctx context.Context, remoteClient *RemoteClient, credentials interface{}) (bool, error)
}
type OnClientConnectFunc func(ctx context.Context, remoteClient *RemoteClient) error
type OnClientConnectHook interface {
OnClientConnect(ctx context.Context, remoteClient *RemoteClient) error
}
type OnClientDisconnectFunc func(ctx context.Context, remoteClient *RemoteClient) error
type OnClientDisconnectHook interface {
OnClientDisconnect(ctx context.Context, remoteClient *RemoteClient) error
}
func DefaultOnClientAuth(ctx context.Context, remoteClient *RemoteClient, credentials interface{}) (bool, error) {
return true, nil
}
func DefaultOnClientConnect(ctx context.Context, remoteClient *RemoteClient) error {
logger.Debug(ctx, "client connected")
return nil
}
func DefaultOnClientDisconnect(ctx context.Context, remoteClient *RemoteClient) error {
logger.Debug(ctx, "client disconnected")
return nil
}
type ServerHooks struct {
onClientAuth OnClientAuthFunc
onClientConnect OnClientConnectFunc
onClientDisconnect OnClientDisconnectFunc
}
func (h *ServerHooks) OnClientAuth(ctx context.Context, remoteClient *RemoteClient, credentials interface{}) (bool, error) {
return h.onClientAuth(ctx, remoteClient, credentials)
}
func (h *ServerHooks) OnClientConnect(ctx context.Context, remoteClient *RemoteClient) error {
return h.onClientConnect(ctx, remoteClient)
}
func (h *ServerHooks) OnClientDisconnect(ctx context.Context, remoteClient *RemoteClient) error {
return h.onClientDisconnect(ctx, remoteClient)
}