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

Libp2p examples #185

Merged
merged 3 commits into from
Mar 30, 2017
Merged

Libp2p examples #185

merged 3 commits into from
Mar 30, 2017

Conversation

hsanjuan
Copy link
Contributor

Improved echo example

Added example for multicodecs

Related to ipfs-inactive/docs#17

@hsanjuan hsanjuan self-assigned this Mar 15, 2017
@hsanjuan hsanjuan added the status/in-progress In progress label Mar 15, 2017
@ghost ghost mentioned this pull request Mar 16, 2017
8 tasks
@hsanjuan
Copy link
Contributor Author

Added http-proxy example

@hsanjuan hsanjuan force-pushed the libp2p-examples branch 2 times, most recently from eb9b182 to 15bf00c Compare March 22, 2017 17:09
* Do not use testutil to generate random keys and ids since this is a testing
dependency. Use crypto.GenerateKeyPair() instead.
* Echo full lines
* Improve output by telling the user what to run
* More code comments

License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
fmt.Fprintf(os.Stderr, "%s\n", err)
}

func die(err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of die, we could use log.Fatalln from go's log package

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I feel bad when I log errors to stdout :(

Copy link
Contributor

Choose a reason for hiding this comment

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

the log subpackage logs to stderr though, so you don't have to feel bad!

req.URL.Host = req.Host

outreq := new(http.Request)
*outreq = *req
Copy link
Contributor

Choose a reason for hiding this comment

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

you could just do:

outreq := *req

for the same effect

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mm yeah fair enough. I copied from https://golang.org/src/net/http/httputil/reverseproxy.go?s=3845:3920#L121 but since we don't pass it around it's ok as you write it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nah, need to pass *http.Request to RoundTrip. I'll leave it as it is, in case someone wants to improve it borrowing more stuff from the reverseproxy.go.

Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM

}

func main() {
// Choose random ports between 10000-10100
Copy link
Contributor

Choose a reason for hiding this comment

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

You can also just use port 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's useful but then I have to use more lines to figure out which ephemeral port was picked up...

Copy link
Contributor

@whyrusleeping whyrusleeping left a comment

Choose a reason for hiding this comment

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

Mostly LGTM. Some cleaning up around logging would be good, but this seems to be a pretty useful example

@hsanjuan
Copy link
Contributor Author

@whyrusleeping changed the logging. Thanks!

Copy link
Contributor

@whyrusleeping whyrusleeping left a comment

Choose a reason for hiding this comment

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

LGTM

@whyrusleeping
Copy link
Contributor

The tests are unhappy in my other PR, lets see if theyre happy here or not

The example proxies http requests through a libp2p stream.

License: MIT
Signed-off-by: Hector Sanjuan <hector@protocol.ai>
@hsanjuan
Copy link
Contributor Author

@whyrusleeping heads up, tests are veery happy here :)

@whyrusleeping whyrusleeping merged commit c5aa669 into master Mar 30, 2017
@whyrusleeping whyrusleeping deleted the libp2p-examples branch March 30, 2017 17:08
@whyrusleeping whyrusleeping removed the status/in-progress In progress label Mar 30, 2017
marten-seemann pushed a commit that referenced this pull request Apr 21, 2022
marten-seemann added a commit that referenced this pull request Aug 9, 2022
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.

None yet

2 participants