示例#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
文件: metrics.go 项目: twocool/srvdir
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),
	}
}
示例#4
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
}
示例#5
0
文件: session.go 项目: 40a/go-tunnel
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,
	}
}
示例#6
0
文件: conn.go 项目: postfix/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
}
示例#7
0
文件: conn.go 项目: postfix/go-tunnel
func (c *Logged) SetTags(tags ...string) {
	c.Logger = log.NewTaggedLogger(tags...)
}
示例#8
0
文件: conn.go 项目: postfix/go-tunnel
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 {