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

Added example "chat" with README #284

Merged
merged 1 commit into from
Mar 3, 2018
Merged

Conversation

upperwal
Copy link
Contributor

@upperwal upperwal commented Feb 26, 2018

Please let me know if this chat application is worth adding to the example folder.

This example demonstrate connecting two peers and opening a stream and chat on that stream. It can work if both the peers are on the same network or if any one of them has a public IP address.

@Stebalien can you please review this PR.
Let me know if some changes needs to be done.
Chat app

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

Thanks! New examples are always nice.


## Build

First install libp2p using `go get -d github.com/libp2p/go-libp2p/...`
Copy link
Member

Choose a reason for hiding this comment

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

We generally manage our dependencies using a tool called gx (to avoid random breakage when our dependencies change). This should probably say:

To build the example, first run make deps in the root directory.

go writeData(rw)

// Hang forever
select {}
Copy link
Member

Choose a reason for hiding this comment

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

This isn't necessary. The stream will stay open until you close it (or the other side closes it).

r := rand.New(rand.NewSource(int64(*sourcePort)))

// Creates a new RSA key pair for this host
prvKey, pubKey, err := crypto.GenerateKeyPairWithReader(crypto.RSA, 1024, r)
Copy link
Member

Choose a reason for hiding this comment

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

Even though this is just an example, I'd rather use a 2048 bit key in case someone copies this code. 1024bit RSA has been deprecated for a while.

}

// Constant random source. This will always generate the same host ID on multiple execution.
r := rand.New(rand.NewSource(int64(*sourcePort)))
Copy link
Member

Choose a reason for hiding this comment

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

Please add a note to not do this in production code 😆.

// IP will be 0.0.0.0 (listen on any interface) and port will be 0 (choose one for me).
// Although this node will not listen for any connection. It will just initiate a connect with
// one of its peer and use that stream to communicate.
fmt.Printf("%s/ipfs/%s\n", sourceMultiAddr, peer.IDB58Encode(host.ID()))
Copy link
Member

Choose a reason for hiding this comment

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

The idiomatic way to pretty format the peer ID is host.ID().Pretty().

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

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

Sorry, wrong button (needs few changes).

@upperwal upperwal force-pushed the master branch 3 times, most recently from cf8f426 to 38f180c Compare March 3, 2018 08:26
@upperwal
Copy link
Contributor Author

upperwal commented Mar 3, 2018

@Stebalien Updated. Also added debug mode where user can choose between random or constant node id's.

can you help me with codecov/project, it is failing but I don't know why.

For future PR's: It is fine to have multiple commits for a PR, if they make sense. It was a headache to squash commits for this one, it was messing up everything, I had to hard reset and add everything again.

@Stebalien
Copy link
Member

It is fine to have multiple commits for a PR, if they make sense.

Yes. However, reverse-merges (e.g., merging master into a feature branch) are generally not.

However, squashing should generally be pretty straight forward. The stupid "works every time" method is just git reset origin/master (note the lack of --hard, this command resets the "index" to that of master but doesn't undo any of the changes) and then re-add all of your changes. However, you can usually do an interactive rebase (git rebase -i origin/master).

@Stebalien
Copy link
Member

can you help me with codecov/project, it is failing but I don't know why.

Ignore this. We probably need to better configure it to ignore examples.

@Stebalien Stebalien merged commit 5180df8 into libp2p:master Mar 3, 2018
@Stebalien
Copy link
Member

Thanks!

@upperwal
Copy link
Contributor Author

upperwal commented Mar 4, 2018

Ok. Thanks!

@lowesyang
Copy link

That's very nice!

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.

3 participants