-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
There was a problem hiding this 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.
examples/chat/README.md
Outdated
|
||
## Build | ||
|
||
First install libp2p using `go get -d github.com/libp2p/go-libp2p/...` |
There was a problem hiding this comment.
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.
examples/chat/chat.go
Outdated
go writeData(rw) | ||
|
||
// Hang forever | ||
select {} |
There was a problem hiding this comment.
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).
examples/chat/chat.go
Outdated
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) |
There was a problem hiding this comment.
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.
examples/chat/chat.go
Outdated
} | ||
|
||
// Constant random source. This will always generate the same host ID on multiple execution. | ||
r := rand.New(rand.NewSource(int64(*sourcePort))) |
There was a problem hiding this comment.
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 😆.
examples/chat/chat.go
Outdated
// 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())) |
There was a problem hiding this comment.
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()
.
There was a problem hiding this 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).
cf8f426
to
38f180c
Compare
@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. |
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 |
Ignore this. We probably need to better configure it to ignore examples. |
Thanks! |
Ok. Thanks! |
That's very nice! |
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.