2019-07-10 17:41:17 +01:00
|
|
|
// Package tunnel provides a network tunnel ontop of a link
|
2019-07-10 17:36:04 +01:00
|
|
|
package tunnel
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/micro/go-micro/network/link"
|
|
|
|
"github.com/micro/go-micro/transport"
|
|
|
|
)
|
|
|
|
|
2019-07-10 17:41:17 +01:00
|
|
|
// Tunnel creates a network tunnel on top of a link.
|
|
|
|
// It establishes multiple streams using the Micro-Tunnel header
|
|
|
|
// created as a hash of the address.
|
2019-07-10 17:36:04 +01:00
|
|
|
type Tunnel interface {
|
|
|
|
// Connect connects the tunnel
|
|
|
|
Connect() error
|
|
|
|
// Close closes the tunnel
|
|
|
|
Close() error
|
|
|
|
// Dial an endpoint
|
|
|
|
Dial(addr string) (Conn, error)
|
|
|
|
// Accept connections
|
2019-07-10 18:24:03 +01:00
|
|
|
Listen(addr string) (Listener, error)
|
|
|
|
}
|
|
|
|
|
2019-07-10 18:26:11 +01:00
|
|
|
// The listener provides similar constructs to the transport.Listener
|
2019-07-10 18:24:03 +01:00
|
|
|
type Listener interface {
|
|
|
|
Addr() string
|
|
|
|
Close() error
|
|
|
|
Accept() (Conn, error)
|
2019-07-10 17:36:04 +01:00
|
|
|
}
|
|
|
|
|
2019-07-10 18:26:11 +01:00
|
|
|
// Conn is a connection dialed or accepted which includes the tunnel id and session
|
2019-07-10 17:36:04 +01:00
|
|
|
type Conn interface {
|
|
|
|
// Specifies the tunnel id
|
|
|
|
Id() string
|
2019-07-10 18:26:11 +01:00
|
|
|
// The session
|
|
|
|
Session() string
|
2019-07-10 17:36:04 +01:00
|
|
|
// a transport socket
|
|
|
|
transport.Socket
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewTunnel creates a new tunnel on top of a link
|
|
|
|
func NewTunnel(l link.Link) Tunnel {
|
|
|
|
return newTunnel(l)
|
|
|
|
}
|