2019-08-07 19:44:33 +02:00
|
|
|
// Package tunnel provides gre network tunnelling
|
2019-08-05 18:52:57 +02:00
|
|
|
package tunnel
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/micro/go-micro/transport"
|
|
|
|
)
|
|
|
|
|
2019-08-07 19:44:33 +02:00
|
|
|
// Tunnel creates a gre network tunnel on top of a link.
|
|
|
|
// It establishes multiple streams using the Micro-Tunnel-Id header
|
|
|
|
// and Micro-Tunnel-Session header. The tunnel id is a hash of
|
|
|
|
// the address being requested.
|
2019-08-05 18:52:57 +02:00
|
|
|
type Tunnel interface {
|
2019-08-07 22:58:25 +02:00
|
|
|
Init(opts ...Option) error
|
2019-08-21 13:55:10 +02:00
|
|
|
// Address the tunnel is listening on
|
|
|
|
Address() string
|
2019-08-05 18:52:57 +02:00
|
|
|
// Connect connects the tunnel
|
|
|
|
Connect() error
|
|
|
|
// Close closes the tunnel
|
|
|
|
Close() error
|
2019-08-07 19:44:33 +02:00
|
|
|
// Dial an endpoint
|
|
|
|
Dial(addr string) (Conn, error)
|
|
|
|
// Accept connections
|
|
|
|
Listen(addr string) (Listener, error)
|
2019-08-20 18:21:35 +02:00
|
|
|
// Name of the tunnel implementation
|
|
|
|
String() string
|
2019-08-07 19:44:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// The listener provides similar constructs to the transport.Listener
|
|
|
|
type Listener interface {
|
|
|
|
Addr() string
|
|
|
|
Close() error
|
|
|
|
Accept() (Conn, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Conn is a connection dialed or accepted which includes the tunnel id and session
|
|
|
|
type Conn interface {
|
|
|
|
// Specifies the tunnel id
|
|
|
|
Id() string
|
|
|
|
// The session
|
|
|
|
Session() string
|
|
|
|
// a transport socket
|
|
|
|
transport.Socket
|
2019-08-05 20:41:48 +02:00
|
|
|
}
|
|
|
|
|
2019-08-07 19:44:33 +02:00
|
|
|
// NewTunnel creates a new tunnel
|
2019-08-05 20:41:48 +02:00
|
|
|
func NewTunnel(opts ...Option) Tunnel {
|
|
|
|
return newTunnel(opts...)
|
2019-08-05 18:52:57 +02:00
|
|
|
}
|