micro/tunnel/default.go

80 lines
1.2 KiB
Go
Raw Normal View History

2019-08-05 21:41:48 +03:00
package tunnel
import (
"sync"
"github.com/micro/go-micro/transport"
)
type tun struct {
sync.RWMutex
2019-08-06 13:45:25 +03:00
tr transport.Transport
options Options
2019-08-05 21:41:48 +03:00
connected bool
closed chan bool
}
func newTunnel(opts ...Option) Tunnel {
// initialize default options
options := DefaultOptions()
for _, o := range opts {
o(&options)
}
2019-08-06 13:45:25 +03:00
// tunnel transport
tr := newTransport()
2019-08-05 21:41:48 +03:00
t := &tun{
2019-08-06 13:45:25 +03:00
tr: tr,
2019-08-05 21:41:48 +03:00
options: options,
closed: make(chan bool),
}
return t
}
2019-08-06 13:45:25 +03:00
// Id returns tunnel id
2019-08-05 21:41:48 +03:00
func (t *tun) Id() string {
return t.options.Id
}
2019-08-06 13:45:25 +03:00
// Options returns tunnel options
func (t *tun) Options() Options {
return t.options
}
// Address returns tunnel listen address
2019-08-05 21:41:48 +03:00
func (t *tun) Address() string {
return t.options.Address
}
2019-08-06 13:45:25 +03:00
// Transport returns tunnel client transport
2019-08-05 21:41:48 +03:00
func (t *tun) Transport() transport.Transport {
2019-08-06 13:45:25 +03:00
return t.tr
2019-08-05 21:41:48 +03:00
}
2019-08-06 13:45:25 +03:00
// Connect connects establishes point to point tunnel
2019-08-05 21:41:48 +03:00
func (t *tun) Connect() error {
return nil
}
2019-08-06 13:45:25 +03:00
// Close closes the tunnel
2019-08-05 21:41:48 +03:00
func (t *tun) Close() error {
return nil
}
2019-08-06 13:45:25 +03:00
// Status returns tunnel status
2019-08-05 21:41:48 +03:00
func (t *tun) Status() Status {
select {
case <-t.closed:
return Closed
default:
return Connected
}
}
func (t *tun) String() string {
return "micro"
}