Tunnel no longer embeds transport
This commit is contained in:
parent
34381213e7
commit
6b5dcbf814
67
tunnel/default.go
Normal file
67
tunnel/default.go
Normal file
@ -0,0 +1,67 @@
|
||||
package tunnel
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/micro/go-micro/transport"
|
||||
)
|
||||
|
||||
type tun struct {
|
||||
options Options
|
||||
sync.RWMutex
|
||||
connected bool
|
||||
closed chan bool
|
||||
}
|
||||
|
||||
func newTunnel(opts ...Option) Tunnel {
|
||||
// initialize default options
|
||||
options := DefaultOptions()
|
||||
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
|
||||
t := &tun{
|
||||
options: options,
|
||||
closed: make(chan bool),
|
||||
}
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *tun) Id() string {
|
||||
return t.options.Id
|
||||
}
|
||||
|
||||
func (t *tun) Address() string {
|
||||
return t.options.Address
|
||||
}
|
||||
|
||||
func (t *tun) Transport() transport.Transport {
|
||||
return t.options.Transport
|
||||
}
|
||||
|
||||
func (t *tun) Options() transport.Options {
|
||||
return transport.Options{}
|
||||
}
|
||||
|
||||
func (t *tun) Connect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *tun) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *tun) Status() Status {
|
||||
select {
|
||||
case <-t.closed:
|
||||
return Closed
|
||||
default:
|
||||
return Connected
|
||||
}
|
||||
}
|
||||
|
||||
func (t *tun) String() string {
|
||||
return "micro"
|
||||
}
|
@ -5,11 +5,33 @@ import (
|
||||
"github.com/micro/go-micro/transport"
|
||||
)
|
||||
|
||||
// Status is tunnel status
|
||||
type Status int
|
||||
|
||||
const (
|
||||
// Connected means the tunnel is alive
|
||||
Connected Status = iota
|
||||
// Closed meands the tunnel has been disconnected
|
||||
Closed
|
||||
)
|
||||
|
||||
// Tunnel creates a p2p network tunnel.
|
||||
type Tunnel interface {
|
||||
transport.Transport
|
||||
// Id returns tunnel id
|
||||
Id() string
|
||||
// Address returns tunnel address
|
||||
Address() string
|
||||
// Tramsport returns tunnel transport
|
||||
Transport() transport.Transport
|
||||
// Connect connects the tunnel
|
||||
Connect() error
|
||||
// Close closes the tunnel
|
||||
Close() error
|
||||
// Status returns tunnel status
|
||||
Status() Status
|
||||
}
|
||||
|
||||
// NewTunnel creates a new tunnel on top of a link
|
||||
func NewTunnel(opts ...Option) Tunnel {
|
||||
return newTunnel(opts...)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user