Skip to content

Commit

Permalink
Replace Connection.RemoteAddr() by Connection() (open-telemetry#171)
Browse files Browse the repository at this point in the history
I am implementing TLS in the example server and found that I need access
to the underlying net.Conn. I added Connection() method to access it.
Now that we have access to net.Conn, RemoteAddr() is no longer needed,
it can be substituted by Connection().RemoteAddr().
  • Loading branch information
tigrannajaryan committed Jun 19, 2023
1 parent df80f77 commit 0f80e80
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions server/httpconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ type httpConnection struct {
conn net.Conn
}

func (c httpConnection) RemoteAddr() net.Addr {
return c.conn.RemoteAddr()
func (c httpConnection) Connection() net.Conn {
return c.conn
}

var _ types.Connection = (*httpConnection)(nil)
Expand Down
2 changes: 1 addition & 1 deletion server/serverimpl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestServerStartAcceptConnection(t *testing.T) {
assert.True(t, atomic.LoadInt32(&connectionCloseCalled) == 0)

// Verify that the RemoteAddr is correct.
require.Equal(t, conn.LocalAddr().String(), srvConn.RemoteAddr().String())
require.Equal(t, conn.LocalAddr().String(), srvConn.Connection().RemoteAddr().String())

// Close the connection from client side.
conn.Close()
Expand Down
4 changes: 2 additions & 2 deletions server/types/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
// Connection represents one OpAMP connection.
// The implementation MUST be a comparable type so that it can be used as a map key.
type Connection interface {
// RemoteAddr returns the remote network address of the connection.
RemoteAddr() net.Addr
// Connection returns the underlying net.Conn
Connection() net.Conn

// Send a message. Should not be called concurrently for the same Connection instance.
// Can be called only for WebSocket connections. Will return an error for plain HTTP
Expand Down
4 changes: 2 additions & 2 deletions server/wsconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ type wsConnection struct {

var _ types.Connection = (*wsConnection)(nil)

func (c wsConnection) RemoteAddr() net.Addr {
return c.wsConn.RemoteAddr()
func (c wsConnection) Connection() net.Conn {
return c.wsConn.UnderlyingConn()
}

// Message header is currently uint64 zero value.
Expand Down

0 comments on commit 0f80e80

Please sign in to comment.