Skip to content

Initialize P2P communication #87

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

Merged
merged 28 commits into from
Jul 29, 2019
Merged

Initialize P2P communication #87

merged 28 commits into from
Jul 29, 2019

Conversation

sukrawidhyawan
Copy link
Contributor

@sukrawidhyawan sukrawidhyawan commented Jul 22, 2019

Description

Initialize basic p2p Communication. For now available service is maintained connected peers & get more peers. Package service in p2p native will separate from unit test and just functional test (script for test not yet add in this PR) and the rest package still in unit test

Breakdown

  • Add P2P strategy (design not fix yet)
  • Add native strategy
  • Available native service: resolvePeers & getMorePeers
  • Peer cycling mechanism (WIP)

Reference Issue

Close #12 #71

Step to Test (optional)

  • run go run main.go, go run main.go -postfix 2, go run main.go -postfix 3 in 3 separate terminal tabs to run 3 nodes based on 3 different configuration files
  • while they are running, observe the ResolvedPeers and UnresolvedPeers populated and cycled through by running go run api/client/GetHostInfo/client.go -ip 127.0.0.1:3001, go run api/client/GetHostInfo/client.go -ip 127.0.0.1:3002 and go run api/client/GetHostInfo/client.go -ip 127.0.0.1:3001 to observe the the state of the 3 nodes seperately

Screen Shot 2019-07-25 at 16 45 12

@capt4ce capt4ce changed the title Initialize P2P communication [WIP] Initialize P2P communication Jul 22, 2019
@capt4ce
Copy link
Contributor

capt4ce commented Jul 22, 2019

Waiting for my enhancement to be included

@capt4ce capt4ce added the WIP label Jul 24, 2019
@sukrawidhyawan sukrawidhyawan added this to the Sprint 2 milestone Jul 26, 2019
@capt4ce capt4ce removed the WIP label Jul 26, 2019
@capt4ce capt4ce changed the title [WIP] Initialize P2P communication Initialize P2P communication Jul 26, 2019
@capt4ce capt4ce mentioned this pull request Jul 26, 2019
2 tasks

// GetMorePeers to collect more peers available
func (psc *PeerServiceClient) GetMorePeers(destPeer *model.Peer) (*model.GetMorePeersResponse, error) {
connection, _ := nativeUtil.GrpcDialer(destPeer)
Copy link
Contributor

Choose a reason for hiding this comment

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

GetMorePreers, 'GetPeerInfo' and SendPeers try to new handshake connection more and more and more.
or need to figure it out how to control this connection for more efficient way.

Copy link
Contributor

Choose a reason for hiding this comment

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

we'll get back to this if it is still in concern in the future #97

@andy-shi88
Copy link
Contributor

another thought: p2p/native/service/client.go:NewPeerService() is lazyly instantiated, using traditional way of keeping it singleton is not enough, may consider using sync.once to avoid multiple go routine instantiating it.

@capt4ce
Copy link
Contributor

capt4ce commented Jul 26, 2019

another thought: p2p/native/service/client.go:NewPeerService() is lazyly instantiated, using traditional way of keeping it singleton is not enough, may consider using sync.once to avoid multiple go routine instantiating it.

Good point. Changed the implementation to use sync.Once

@andy-shi88
Copy link
Contributor

and for secure random, we can use https://golang.org/pkg/crypto/rand/

@capt4ce
Copy link
Contributor

capt4ce commented Jul 26, 2019

@andy-shi88 Thanks, @sukrawidhyawan has perform it.
Just keeping a note here that we need to analyze the performance of crypto/random

@andy-shi88 andy-shi88 merged commit 1e714e0 into develop Jul 29, 2019
@andy-shi88 andy-shi88 deleted the 12-init-p2p branch July 29, 2019 02:03
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.

Tech: basic p2p node communication. Discovery and broadcast message
5 participants