func NewRegistrationHooks(onAuthURL, onBindURL string) *RegistrationHooks { return &RegistrationHooks{ Logger: log.NewTaggedLogger("hooks", "registration"), onAuthURL: onAuthURL, onBindURL: onBindURL, } }
// Create a new tunnel from a registration message received // on a control channel func newTunnel(b *proto.Bind, sess *Session, binders Binders, hooks TunnelHooks) (t *Tunnel, err error) { t = &Tunnel{ req: b, start: time.Now(), sess: sess, Logger: log.NewTaggedLogger(sess.id, "tunnel"), hooks: hooks, } binder, ok := binders[t.req.Protocol] if !ok { return nil, fmt.Errorf("Can't bind for %s connections", t.req.Protocol) } if t.listener, t.url, err = binder.Bind(b.Options); err != nil { return } go t.listen(t.listener) // update the logger t.Logger.AddTags(t.url) // tunnel hook if err = t.hooks.OnTunnelOpen(t); err != nil { return } return }
func NewMetricsHooks(keenApiKey, keenProjectToken string) *MetricsHooks { client := &keen.Client{WriteKey: keenApiKey, ProjectID: keenProjectToken} return &MetricsHooks{ Logger: log.NewTaggedLogger("hooks", "metrics"), client: keen.NewBatchClient(client, flushInterval), } }
// Creates a new client tunnel session with the given id // running over the given muxado session. func NewRawSession(mux muxado.Session) *RawSession { sess := &RawSession{ mux: mux, Logger: log.NewTaggedLogger("session"), } return sess }
func NewSession(mux muxado.Session, registry *sessionRegistry, sessHooks SessionHooks, tunnelHooks TunnelHooks, binders Binders) *Session { return &Session{ Logger: log.NewTaggedLogger("session"), mux: mux, tunnels: make(map[string]*Tunnel, 0), registry: registry, hooks: sessHooks, binders: binders, tunnelHooks: tunnelHooks, } }
func wrapConn(conn net.Conn, tags ...string) *Logged { switch c := conn.(type) { case *Logged: return c default: logged := &Logged{Conn: conn, Logger: log.NewTaggedLogger(util.RandId(4))} logged.AddTags(tags...) return logged } return nil }
func (c *Logged) SetTags(tags ...string) { c.Logger = log.NewTaggedLogger(tags...) }
package conn import ( "crypto/tls" log "github.com/inconshreveable/go-tunnel/log" util "github.com/inconshreveable/go-tunnel/util" "io" "net" "sync" ) var ( logger = log.NewTaggedLogger("go-tunnel/conn") ) type Conn interface { net.Conn log.Logger } type Logged struct { net.Conn log.Logger } type Listener struct { net.Addr Conns chan *Logged } func wrapConn(conn net.Conn, tags ...string) *Logged {