Rough outline of tunnel types

This commit is contained in:
Milos Gajdos 2019-08-06 11:45:25 +01:00
parent 000431f489
commit 4074cce397
No known key found for this signature in database
GPG Key ID: 8B31058CC55DFD4F
4 changed files with 97 additions and 7 deletions

View File

@ -7,8 +7,9 @@ import (
) )
type tun struct { type tun struct {
options Options
sync.RWMutex sync.RWMutex
tr transport.Transport
options Options
connected bool connected bool
closed chan bool closed chan bool
} }
@ -21,7 +22,11 @@ func newTunnel(opts ...Option) Tunnel {
o(&options) o(&options)
} }
// tunnel transport
tr := newTransport()
t := &tun{ t := &tun{
tr: tr,
options: options, options: options,
closed: make(chan bool), closed: make(chan bool),
} }
@ -29,30 +34,37 @@ func newTunnel(opts ...Option) Tunnel {
return t return t
} }
// Id returns tunnel id
func (t *tun) Id() string { func (t *tun) Id() string {
return t.options.Id 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 { func (t *tun) Address() string {
return t.options.Address return t.options.Address
} }
// Transport returns tunnel client transport
func (t *tun) Transport() transport.Transport { func (t *tun) Transport() transport.Transport {
return nil return t.tr
}
func (t *tun) Options() transport.Options {
return transport.Options{}
} }
// Connect connects establishes point to point tunnel
func (t *tun) Connect() error { func (t *tun) Connect() error {
return nil return nil
} }
// Close closes the tunnel
func (t *tun) Close() error { func (t *tun) Close() error {
return nil return nil
} }
// Status returns tunnel status
func (t *tun) Status() Status { func (t *tun) Status() Status {
select { select {
case <-t.closed: case <-t.closed:

25
tunnel/socket.go Normal file
View File

@ -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 ""
}

51
tunnel/transport.go Normal file
View File

@ -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"
}

View File

@ -19,9 +19,11 @@ const (
type Tunnel interface { type Tunnel interface {
// Id returns tunnel id // Id returns tunnel id
Id() string Id() string
// Options returns the tunnel options
Options() Options
// Address returns tunnel address // Address returns tunnel address
Address() string Address() string
// Tramsport returns tunnel transport // Transport to use by tunne clients
Transport() transport.Transport Transport() transport.Transport
// Connect connects the tunnel // Connect connects the tunnel
Connect() error Connect() error