Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the RemoteAddr via the Connection interface #57

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions server/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"context"
"net"

"github.com/gorilla/websocket"
"google.golang.org/protobuf/proto"
Expand All @@ -16,6 +17,10 @@ type connection struct {

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

func (c connection) RemoteAddr() net.Addr {
return c.RemoteAddr()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this recursively calling itself or I am misreading the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't read that wrong. I put this PR together quickly to begin discussion and it was an oversight. It clearly needs a test case as well.

}

func (c connection) Send(ctx context.Context, message *protobufs.ServerToAgent) error {
bytes, err := proto.Marshal(message)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion server/serverimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (s *server) httpHandler(w http.ResponseWriter, req *http.Request) {
}

// Return from this func to reduce memory usage.
// Handle the connection on a separate gorountine.
// Handle the connection on a separate goroutine.
go s.handleWSConnection(conn)
}

Expand Down
4 changes: 4 additions & 0 deletions server/types/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ package types

import (
"context"
"net"

"github.com/open-telemetry/opamp-go/protobufs"
)

// Connection represents one OpAMP WebSocket connections.
// The implementation MUST be a comparable type so that it can be used as a map key.
type Connection interface {
Copy link
Member

@tigrannajaryan tigrannajaryan Mar 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andykellr to support the use case that you have I think we also need to add net.Conn as a field. This will allow to access the TLS certificate. I believe net.Conn is accessible for WebSocket (UnderlyingConn() in ws gorilla). If you can confirm it is also accessible for gRPC connections and for plain HTTP connections then it should be OK to add it to this interface.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andykellr this PR looks good to me now. I will merge as is and you can address this comment in a separate PR if you need the Conn.

// RemoteAddr returns the remote network address of the connection.
RemoteAddr() net.Addr

// Send a message. Should not be called concurrently for the same Connection instance.
// Blocks until the message is sent.
// Should return as soon as possible if the ctx is cancelled.
Expand Down