Exemplo n.º 1
0
func NewRegistrationHooks(onAuthURL, onBindURL string) *RegistrationHooks {
	return &RegistrationHooks{
		Logger:    log.NewTaggedLogger("hooks", "registration"),
		onAuthURL: onAuthURL,
		onBindURL: onBindURL,
	}
}
Exemplo n.º 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
}
Exemplo n.º 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
}
Exemplo n.º 4
0
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),
	}
}
Exemplo n.º 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),
	}
}
Exemplo n.º 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,
	}
}
Exemplo n.º 7
0
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
}
Exemplo n.º 8
0
func (c *Logged) SetTags(tags ...string) {
	c.Logger = log.NewTaggedLogger(tags...)
}
Exemplo n.º 9
0
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 {