示例#1
0
func NewRegistrationHooks(onAuthURL, onBindURL string) *RegistrationHooks {
	return &RegistrationHooks{
		Logger:    log.NewTaggedLogger("hooks", "registration"),
		onAuthURL: onAuthURL,
		onBindURL: onBindURL,
	}
}
示例#2
0
// 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
}
示例#3
0
// 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
}
示例#4
0
文件: metrics.go 项目: jmcarbo/srvdir
func NewMetricsHooks(keenApiKey, keenProjectToken string) *MetricsHooks {
	client := &keen.Client{ApiKey: keenApiKey, ProjectToken: keenProjectToken}

	return &MetricsHooks{
		Logger: log.NewTaggedLogger("hooks", "metrics"),
		client: keen.NewBatchClient(client, flushInterval),
	}
}
示例#5
0
// NewServer creates a new server which binds tunnels with binders on sessions
// it accepts from the given listener.
func NewServer(listener net.Listener, binders Binders) *Server {
	return &Server{
		Logger:       log.NewTaggedLogger("server", listener.Addr().String()),
		listener:     muxado.NewListener(listener),
		registry:     NewSessionRegistry(),
		Binders:      binders,
		TunnelHooks:  new(NoopTunnelHooks),
		SessionHooks: new(NoopSessionHooks),
	}
}
示例#6
0
func NewSession(mux muxado.Session, registry *sessionRegistry, sessHooks SessionHooks, tunnelHooks TunnelHooks, binders Binders) *Session {
	return &Session{
		start:       time.Now(),
		Logger:      log.NewTaggedLogger("session"),
		mux:         mux,
		tunnels:     make(map[string]*Tunnel, 0),
		registry:    registry,
		hooks:       sessHooks,
		binders:     binders,
		tunnelHooks: tunnelHooks,
	}
}
示例#7
0
文件: conn.go 项目: jmcarbo/go-tunnel
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
}
示例#8
0
文件: conn.go 项目: jmcarbo/go-tunnel
func (c *Logged) SetTags(tags ...string) {
	c.Logger = log.NewTaggedLogger(tags...)
}
示例#9
0
文件: conn.go 项目: jmcarbo/go-tunnel
package conn

import (
	"crypto/tls"
	log "github.com/jmcarbo/go-tunnel/log"
	util "github.com/jmcarbo/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 {