Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Add chat example with tor support #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

bigs
Copy link
Contributor

@bigs bigs commented Jul 27, 2018

unsure if we want to have this as chat-with-tor or replace the old chat but given recent conversations about having a dead simple peer discovery example, it may make sense to leave the chat example alone and update it later.

@bigs bigs requested a review from Stebalien July 27, 2018 21:15
@Stebalien
Copy link
Member

Blocked on OpenBazaar/go-onion-transport#3.

@Stebalien Stebalien added the status/blocked Unable to be worked further until needs are met label Jul 27, 2018
@@ -0,0 +1,14 @@
deps:
go get -u 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.

You should be able to just run go get -u ./.... Does that not work?

go get -u github.com/OpenBazaar/openbazaar-go/net

build:
go build -o libp2p-demo *.go
Copy link
Member

Choose a reason for hiding this comment

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

Does go build not work?

@@ -0,0 +1,15 @@
# libp2p-chat-app
Copy link
Member

Choose a reason for hiding this comment

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

Wrong package?

# libp2p-chat-app
Chat app demo based on @whyrusleeping's gist.

# Instructions
Copy link
Member

Choose a reason for hiding this comment

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

Should probably be heading level 2.

Install deps and build:

```shell
$ make deps
Copy link
Member

Choose a reason for hiding this comment

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

Given that we're not using gx, I'd almost just remove the make file and tell users to run:

> go get -u ./...
> go build # or maybe just `go run`?

To start, make sure you have Go installed and set up. Then install libp2p and some other dependencies we need with:

```shell
$ make deps
Copy link
Member

Choose a reason for hiding this comment

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

Same, go get -u ./... should work. Also note that we have a convention of using > as the shell prefix for reasons I can't recall.

"github.com/libp2p/go-libp2p-peerstore"
"github.com/libp2p/go-libp2p-transport"
"github.com/multiformats/go-multiaddr"
"github.com/multiformats/go-multihash"
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, we really need to start using type aliases. This is nasty!


Next up, lets start constructing the pieces! First, we will set up our libp2p host. The host is the main abstraction that users of go-libp2p will deal with, It lets you connect to other peers, open new streams, and register protocol stream handlers.

Next up, some configuration and initialization. We parse our command-line flags and start working on constructing our libp2p [`Host`](https://godoc.org/github.com/libp2p/go-libp2p-host#Host). We copy the user-provided addresses to listen on and optionally add a tor onion address to listen on if we're using the tor transport. **Note**: Due to some specifics of the tor transport layer's implementation, your local tor instance must be configured such that the SOCKS5 proxy and controller have the **same password**.
Copy link
Member

Choose a reason for hiding this comment

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

Is there any documentation we can link to?

With our new transport configured (in the event that we're using tor), we can create our `Host`. The `Host` object will be most developer's primary point-of-contact with `libp2p`. The `Host` is so-named because it is both a client and a server. Behind the scenes, it manages a whole host (groan) of difficult tasks, including connection management and reuse, stream multiplexing, and encryption. After creating our host, we print out all of the addresses at which it can be reached so that we might tell other clients. This subtly showcases some of `libp2p`'s power, potentially many transports and protocols supported by a single, simple abstraction.

```go
tptOptions := libp2p.Transports(tpts...)
Copy link
Member

Choose a reason for hiding this comment

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

FYI, multiple transport/listen options will be merged into one. You can actually just declare an "options" slice and start appending random options to it (transports, listen addresses, etc).

However, this also works.

@@ -0,0 +1,188 @@
package main
Copy link
Member

Choose a reason for hiding this comment

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

Make sure to keep this code up-to-date with the code in the readme!

vyzo pushed a commit that referenced this pull request Dec 2, 2018
@anacrolix
Copy link
Contributor

Is there still interest in this PR?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status/blocked Unable to be worked further until needs are met
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants