Merge pull request #649 from milosgajdos83/tun-types
Rough outline of tunnel types
This commit is contained in:
		| @@ -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: | ||||
|   | ||||
							
								
								
									
										25
									
								
								tunnel/socket.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								tunnel/socket.go
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										51
									
								
								tunnel/transport.go
									
									
									
									
									
										Normal 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" | ||||
| } | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user