2019-08-07 18:44:33 +01:00
|
|
|
// Package tunnel provides gre network tunnelling
|
2019-08-05 17:52:57 +01:00
|
|
|
package tunnel
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/micro/go-micro/transport"
|
|
|
|
)
|
|
|
|
|
2019-08-31 17:32:20 +01:00
|
|
|
// Tunnel creates a gre tunnel on top of the go-micro/transport.
|
|
|
|
// It establishes multiple streams using the Micro-Tunnel-Channel header
|
2019-08-07 18:44:33 +01:00
|
|
|
// and Micro-Tunnel-Session header. The tunnel id is a hash of
|
|
|
|
// the address being requested.
|
2019-08-05 17:52:57 +01:00
|
|
|
type Tunnel interface {
|
2019-08-07 21:58:25 +01:00
|
|
|
Init(opts ...Option) error
|
2019-08-21 12:55:10 +01:00
|
|
|
// Address the tunnel is listening on
|
|
|
|
Address() string
|
2019-08-05 17:52:57 +01:00
|
|
|
// Connect connects the tunnel
|
|
|
|
Connect() error
|
|
|
|
// Close closes the tunnel
|
|
|
|
Close() error
|
2019-08-30 20:05:00 +01:00
|
|
|
// Connect to a channel
|
|
|
|
Dial(channel string) (Session, error)
|
|
|
|
// Accept connections on a channel
|
|
|
|
Listen(channel string) (Listener, error)
|
2019-08-20 17:21:35 +01:00
|
|
|
// Name of the tunnel implementation
|
|
|
|
String() string
|
2019-08-07 18:44:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// The listener provides similar constructs to the transport.Listener
|
|
|
|
type Listener interface {
|
2019-08-31 17:32:20 +01:00
|
|
|
Accept() (Session, error)
|
2019-08-30 20:05:00 +01:00
|
|
|
Channel() string
|
2019-08-07 18:44:33 +01:00
|
|
|
Close() error
|
|
|
|
}
|
|
|
|
|
2019-08-30 20:05:00 +01:00
|
|
|
// Session is a unique session created when dialling or accepting connections on the tunnel
|
|
|
|
type Session interface {
|
2019-08-31 17:32:20 +01:00
|
|
|
// The unique session id
|
2019-08-07 18:44:33 +01:00
|
|
|
Id() string
|
2019-08-31 17:32:20 +01:00
|
|
|
// The channel name
|
2019-08-30 20:05:00 +01:00
|
|
|
Channel() string
|
2019-08-07 18:44:33 +01:00
|
|
|
// a transport socket
|
|
|
|
transport.Socket
|
2019-08-05 19:41:48 +01:00
|
|
|
}
|
|
|
|
|
2019-08-07 18:44:33 +01:00
|
|
|
// NewTunnel creates a new tunnel
|
2019-08-05 19:41:48 +01:00
|
|
|
func NewTunnel(opts ...Option) Tunnel {
|
|
|
|
return newTunnel(opts...)
|
2019-08-05 17:52:57 +01:00
|
|
|
}
|