| @@ -15,6 +15,8 @@ type testCodec struct { | |||||||
| } | } | ||||||
|  |  | ||||||
| type testSocket struct { | type testSocket struct { | ||||||
|  | 	local  string | ||||||
|  | 	remote string | ||||||
| } | } | ||||||
|  |  | ||||||
| // TestCodecWriteError simulates what happens when a codec is unable | // TestCodecWriteError simulates what happens when a codec is unable | ||||||
| @@ -87,6 +89,14 @@ func (c *testCodec) String() string { | |||||||
| 	return "string" | 	return "string" | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func (s testSocket) Local() string { | ||||||
|  | 	return s.local | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func (s testSocket) Remote() string { | ||||||
|  | 	return s.remote | ||||||
|  | } | ||||||
|  |  | ||||||
| func (s testSocket) Recv(message *transport.Message) error { | func (s testSocket) Recv(message *transport.Message) error { | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|   | |||||||
| @@ -40,6 +40,10 @@ type httpTransportClient struct { | |||||||
| 	r    chan *http.Request | 	r    chan *http.Request | ||||||
| 	bl   []*http.Request | 	bl   []*http.Request | ||||||
| 	buff *bufio.Reader | 	buff *bufio.Reader | ||||||
|  |  | ||||||
|  | 	// local/remote ip | ||||||
|  | 	local  string | ||||||
|  | 	remote string | ||||||
| } | } | ||||||
|  |  | ||||||
| type httpTransportSocket struct { | type httpTransportSocket struct { | ||||||
| @@ -51,6 +55,10 @@ type httpTransportSocket struct { | |||||||
| 	conn net.Conn | 	conn net.Conn | ||||||
| 	// for the first request | 	// for the first request | ||||||
| 	ch chan *http.Request | 	ch chan *http.Request | ||||||
|  |  | ||||||
|  | 	// local/remote ip | ||||||
|  | 	local  string | ||||||
|  | 	remote string | ||||||
| } | } | ||||||
|  |  | ||||||
| type httpTransportListener struct { | type httpTransportListener struct { | ||||||
| @@ -62,6 +70,14 @@ func (b *buffer) Close() error { | |||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func (h *httpTransportClient) Local() string { | ||||||
|  | 	return h.local | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func (h *httpTransportClient) Remote() string { | ||||||
|  | 	return h.remote | ||||||
|  | } | ||||||
|  |  | ||||||
| func (h *httpTransportClient) Send(m *Message) error { | func (h *httpTransportClient) Send(m *Message) error { | ||||||
| 	header := make(http.Header) | 	header := make(http.Header) | ||||||
|  |  | ||||||
| @@ -173,6 +189,14 @@ func (h *httpTransportClient) Close() error { | |||||||
| 	return err | 	return err | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func (h *httpTransportSocket) Local() string { | ||||||
|  | 	return h.local | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func (h *httpTransportSocket) Remote() string { | ||||||
|  | 	return h.remote | ||||||
|  | } | ||||||
|  |  | ||||||
| func (h *httpTransportSocket) Recv(m *Message) error { | func (h *httpTransportSocket) Recv(m *Message) error { | ||||||
| 	if m == nil { | 	if m == nil { | ||||||
| 		return errors.New("message passed in is nil") | 		return errors.New("message passed in is nil") | ||||||
| @@ -374,6 +398,8 @@ func (h *httpTransportListener) Accept(fn func(Socket)) error { | |||||||
| 			rw:     buf, | 			rw:     buf, | ||||||
| 			ch:     ch, | 			ch:     ch, | ||||||
| 			conn:   con, | 			conn:   con, | ||||||
|  | 			local:  h.Addr(), | ||||||
|  | 			remote: r.RemoteAddr, | ||||||
| 		}) | 		}) | ||||||
| 	}) | 	}) | ||||||
|  |  | ||||||
| @@ -430,6 +456,8 @@ func (h *httpTransport) Dial(addr string, opts ...DialOption) (Client, error) { | |||||||
| 		buff:     bufio.NewReader(conn), | 		buff:     bufio.NewReader(conn), | ||||||
| 		dialOpts: dopts, | 		dialOpts: dopts, | ||||||
| 		r:        make(chan *http.Request, 1), | 		r:        make(chan *http.Request, 1), | ||||||
|  | 		local:    conn.LocalAddr().String(), | ||||||
|  | 		remote:   conn.RemoteAddr().String(), | ||||||
| 	}, nil | 	}, nil | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -18,6 +18,9 @@ type mockSocket struct { | |||||||
| 	exit chan bool | 	exit chan bool | ||||||
| 	// listener exit | 	// listener exit | ||||||
| 	lexit chan bool | 	lexit chan bool | ||||||
|  |  | ||||||
|  | 	local  string | ||||||
|  | 	remote string | ||||||
| } | } | ||||||
|  |  | ||||||
| type mockClient struct { | type mockClient struct { | ||||||
| @@ -51,6 +54,14 @@ func (ms *mockSocket) Recv(m *transport.Message) error { | |||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func (ms *mockSocket) Local() string { | ||||||
|  | 	return ms.local | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func (ms *mockSocket) Remote() string { | ||||||
|  | 	return ms.remote | ||||||
|  | } | ||||||
|  |  | ||||||
| func (ms *mockSocket) Send(m *transport.Message) error { | func (ms *mockSocket) Send(m *transport.Message) error { | ||||||
| 	select { | 	select { | ||||||
| 	case <-ms.exit: | 	case <-ms.exit: | ||||||
| @@ -97,6 +108,8 @@ func (m *mockListener) Accept(fn func(transport.Socket)) error { | |||||||
| 				exit:   c.exit, | 				exit:   c.exit, | ||||||
| 				send:   c.recv, | 				send:   c.recv, | ||||||
| 				recv:   c.send, | 				recv:   c.send, | ||||||
|  | 				local:  c.Remote(), | ||||||
|  | 				remote: c.Local(), | ||||||
| 			}) | 			}) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| @@ -122,6 +135,8 @@ func (m *mockTransport) Dial(addr string, opts ...transport.DialOption) (transpo | |||||||
| 			recv:   make(chan *transport.Message), | 			recv:   make(chan *transport.Message), | ||||||
| 			exit:   make(chan bool), | 			exit:   make(chan bool), | ||||||
| 			lexit:  listener.exit, | 			lexit:  listener.exit, | ||||||
|  | 			local:  addr, | ||||||
|  | 			remote: addr, | ||||||
| 		}, | 		}, | ||||||
| 		options, | 		options, | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -14,6 +14,8 @@ type Socket interface { | |||||||
| 	Recv(*Message) error | 	Recv(*Message) error | ||||||
| 	Send(*Message) error | 	Send(*Message) error | ||||||
| 	Close() error | 	Close() error | ||||||
|  | 	Local() string | ||||||
|  | 	Remote() string | ||||||
| } | } | ||||||
|  |  | ||||||
| type Client interface { | type Client interface { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user