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

feat:(conn): add RemoteAddr and LocalAddr method #490

Closed
wants to merge 4 commits into from

Conversation

kehiy
Copy link

@kehiy kehiy commented Sep 15, 2024

@kehiy
Copy link
Author

kehiy commented Sep 15, 2024

@mafredri hi, can you kindly review this, please?

Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

Except for the suggestion inline, the PR looks good. Thanks.

I would be interested in knowing what your use-case is though, how is this feature beneficial to you?

conn.go Outdated Show resolved Hide resolved
@kehiy
Copy link
Author

kehiy commented Sep 17, 2024

@mafredri about use case, several programs need to collect IP address sometimes to use it for spam protection and this kind of stuff. sometimes we have to be aware of who we are talking too. or use it in logs to check whats going on better. in my case we are developing a nostr relay which can be aimed for spam attacks a lot.

@kehiy kehiy requested a review from mafredri September 17, 2024 15:33
@kehiy
Copy link
Author

kehiy commented Sep 17, 2024

@mafredri can you review again please?

accept.go Outdated Show resolved Hide resolved
accept.go Outdated Show resolved Hide resolved
conn.go Outdated Show resolved Hide resolved
@mafredri
Copy link
Member

Since we're adding RemoteAddr() net.Addr, I think it would make sense to add LocalAddr() net.Addr too, do you want to include that in this PR?

@kehiy
Copy link
Author

kehiy commented Sep 18, 2024

@mafredri so, based on your review, i found that we have a netConn as well which i didn't saw it before. so this one is good. to achieve what you say in reviews we have 3 ways:

  1. keeping netConn in Conn struct.
  2. keeping RemoteAddr and/or LocalAddr in Conn struct.
  3. change rwc in Conn to keep the netConn.

which one makes sense in our case?

@kehiy
Copy link
Author

kehiy commented Sep 18, 2024

Since we're adding RemoteAddr() net.Addr, I think it would make sense to add LocalAddr() net.Addr too, do you want to include that in this PR?

i would include it in this pr.

@mafredri
Copy link
Member

You can just do a similar check as done here:

func (nc *netConn) RemoteAddr() net.Addr {
if unc, ok := nc.c.rwc.(net.Conn); ok {
return unc.RemoteAddr()
}
return websocketAddr{}
}
func (nc *netConn) LocalAddr() net.Addr {
if unc, ok := nc.c.rwc.(net.Conn); ok {
return unc.LocalAddr()
}
return websocketAddr{}
}

While you're at it, the linked code can be changed to just return nc.c.RemoteAddr(), etc.

We should also add these methods to the WASM implementation too, even if we can't return any useful information.

@kehiy kehiy requested a review from mafredri September 18, 2024 13:46
@kehiy
Copy link
Author

kehiy commented Sep 18, 2024

@mafredri now both are added based on what you suggest. adding to wasm implementation is remained correct? should it be included in this pr? i need to look at wasm implementation to find out how can i do that.

@kehiy kehiy changed the title feat:(conn): add RemoteAddr method feat:(conn): add RemoteAddr and LocalAddr method Sep 18, 2024
@kehiy kehiy closed this by deleting the head repository Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remote address
2 participants