2019-08-05 19:41:48 +01:00
|
|
|
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 {
|
2019-08-05 21:09:46 +01:00
|
|
|
return nil
|
2019-08-05 19:41:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
|
|
|
}
|