예제 #1
0
func NewRegistrationHooks(onAuthURL, onBindURL string) *RegistrationHooks {
	return &RegistrationHooks{
		Logger:    log.NewTaggedLogger("hooks", "registration"),
		onAuthURL: onAuthURL,
		onBindURL: onBindURL,
	}
}
예제 #2
0
파일: tunnel.go 프로젝트: jmcarbo/go-tunnel
// 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
파일: server.go 프로젝트: jmcarbo/go-tunnel
// 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 {