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

Prevent AddPeerInfo to override existing server information #1752

Merged
merged 4 commits into from
Feb 28, 2024

Conversation

arnauds5
Copy link
Collaborator

Addresses the issue #1748
The AddPeerInfo function is now checking if it already contains a value for the specified socketId before writing the server information.
If it is called with an existing socketId, it will throw an error.

@arnauds5 arnauds5 requested a review from a team as a code owner February 23, 2024 12:01
Copy link

Pull reviewers stats

Stats of the last 30 days for popstellar:

User Total reviews Time to review Total comments
pierluca
🥇
5
▀▀▀▀▀▀
6d 7h 35m
▀▀▀▀▀▀
10
▀▀▀▀▀▀▀▀▀▀
jbsv
🥈
2
▀▀
1d 7h 33m
0
MariemBaccari
🥉
1
3d 54m
▀▀▀
0
K1li4nL
1
18m
0

@arnauds5 arnauds5 linked an issue Feb 23, 2024 that may be closed by this pull request
6 tasks
Copy link
Contributor

@MariemBaccari MariemBaccari left a comment

Choose a reason for hiding this comment

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

Good job, I suggest a minor change before approving.


_, ok := p.peersInfo[socketId]
if ok {
return xerrors.Errorf("peersInfo already contains [%s]", socketId)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the logs would be a bit more readable if they included the peer's info than the socket id. Maybe something like "peersInfo already contains socketid id for server peer's address would be useful for debugging.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I changed it to also include the peer's info.

@arnauds5 arnauds5 added the bug-fix Fixes a bug label Feb 26, 2024
@CLAassistant
Copy link

CLAassistant commented Feb 27, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Collaborator

@sgueissa sgueissa left a comment

Choose a reason for hiding this comment

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

Nice just one little thing to change

Comment on lines 34 to 37
_, ok := p.peersInfo[socketId]
if ok {
return xerrors.Errorf("peersInfo already contains socketId %s for server %s", socketId, info)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should change info inside the xerrors.Errorf by the value you get from p.peersInfo[socketId] because we want to say that the socket is already used by an other server.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or something like 'peersInfo cannot add peer %s because socketId %s already exists'

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you thing that including both values of info could be useful ?
for example "peersInfo cannot add peer new_value because it already contains peer current_value for socketID id"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes but in this case you should only print the peerId without the servers informations for both

Copy link
Collaborator

Choose a reason for hiding this comment

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

peersInfo cannot add new peer new_peerID because socket socketID is already used by peer current_peerID

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

peersInfo is a map of socketId to ServerInfo, maybe the following could be more readable ?
"cannot add new_peer_info because peersInfo[id] already contains current_peer_info"

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think that adding the peer information other than its public key is useful in this case.

Copy link

Quality Gate Passed Quality Gate passed for 'PoP - PoPCHA-Web-Client'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Copy link

Quality Gate Passed Quality Gate passed for 'PoP - Be2-Scala'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Copy link

Copy link

Quality Gate Passed Quality Gate passed for 'PoP - Fe2-Android'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Copy link

Quality Gate Passed Quality Gate passed for 'PoP - Fe1-Web'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

Copy link
Contributor

@MariemBaccari MariemBaccari left a comment

Choose a reason for hiding this comment

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

LGTM

@arnauds5 arnauds5 merged commit 905731a into master Feb 28, 2024
18 checks passed
@arnauds5 arnauds5 deleted the work-be1-arnauds5-no-override-addpeerinfo branch February 28, 2024 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AddPeerInfo can override existing server information
4 participants