diff --git a/tunnel/default.go b/tunnel/default.go index 127785d3..d0eecf51 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -7,8 +7,9 @@ import ( ) type tun struct { - options Options sync.RWMutex + tr transport.Transport + options Options connected bool closed chan bool } @@ -21,7 +22,11 @@ func newTunnel(opts ...Option) Tunnel { o(&options) } + // tunnel transport + tr := newTransport() + t := &tun{ + tr: tr, options: options, closed: make(chan bool), } @@ -29,30 +34,37 @@ func newTunnel(opts ...Option) Tunnel { return t } +// Id returns tunnel id func (t *tun) Id() string { return t.options.Id } +// Options returns tunnel options +func (t *tun) Options() Options { + return t.options +} + +// Address returns tunnel listen address func (t *tun) Address() string { return t.options.Address } +// Transport returns tunnel client transport func (t *tun) Transport() transport.Transport { - return nil -} - -func (t *tun) Options() transport.Options { - return transport.Options{} + return t.tr } +// Connect connects establishes point to point tunnel func (t *tun) Connect() error { return nil } +// Close closes the tunnel func (t *tun) Close() error { return nil } +// Status returns tunnel status func (t *tun) Status() Status { select { case <-t.closed: diff --git a/tunnel/socket.go b/tunnel/socket.go new file mode 100644 index 00000000..ad98287f --- /dev/null +++ b/tunnel/socket.go @@ -0,0 +1,25 @@ +package tunnel + +import "github.com/micro/go-micro/transport" + +type tunSocket struct{} + +func (s *tunSocket) Recv(m *transport.Message) error { + return nil +} + +func (s *tunSocket) Send(m *transport.Message) error { + return nil +} + +func (s *tunSocket) Close() error { + return nil +} + +func (s *tunSocket) Local() string { + return "" +} + +func (s *tunSocket) Remote() string { + return "" +} diff --git a/tunnel/transport.go b/tunnel/transport.go new file mode 100644 index 00000000..fc03398a --- /dev/null +++ b/tunnel/transport.go @@ -0,0 +1,51 @@ +package tunnel + +import "github.com/micro/go-micro/transport" + +type tunTransport struct { + options transport.Options +} + +type tunClient struct { + *tunSocket + options transport.DialOptions +} + +type tunListener struct { + conn chan *tunSocket +} + +func newTransport(opts ...transport.Option) transport.Transport { + var options transport.Options + + for _, o := range opts { + o(&options) + } + + return &tunTransport{ + options: options, + } +} + +func (t *tunTransport) Init(opts ...transport.Option) error { + for _, o := range opts { + o(&t.options) + } + return nil +} + +func (t *tunTransport) Options() transport.Options { + return t.options +} + +func (t *tunTransport) Dial(addr string, opts ...transport.DialOption) (transport.Client, error) { + return nil, nil +} + +func (t *tunTransport) Listen(addr string, opts ...transport.ListenOption) (transport.Listener, error) { + return nil, nil +} + +func (t *tunTransport) String() string { + return "micro" +} diff --git a/tunnel/tunnel.go b/tunnel/tunnel.go index 2adc4447..55bcd809 100644 --- a/tunnel/tunnel.go +++ b/tunnel/tunnel.go @@ -19,9 +19,11 @@ const ( type Tunnel interface { // Id returns tunnel id Id() string + // Options returns the tunnel options + Options() Options // Address returns tunnel address Address() string - // Tramsport returns tunnel transport + // Transport to use by tunne clients Transport() transport.Transport // Connect connects the tunnel Connect() error