-
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
Libp2p examples #185
Libp2p examples #185
Conversation
95c4283
to
9c0e31c
Compare
Added http-proxy example |
eb9b182
to
15bf00c
Compare
* 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 <[email protected]>
License: MIT Signed-off-by: Hector Sanjuan <[email protected]>
15bf00c
to
e9d0fc7
Compare
examples/http-proxy/proxy.go
Outdated
fmt.Fprintf(os.Stderr, "%s\n", err) | ||
} | ||
|
||
func die(err error) { |
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.
Instead of die
, we could use log.Fatalln
from go's log package
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.
But I feel bad when I log errors to stdout :(
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 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 |
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.
you could just do:
outreq := *req
for the same effect
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.
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.
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.
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
.
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.
SGTM
} | ||
|
||
func main() { | ||
// Choose random ports between 10000-10100 |
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.
You can also just use port 0
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.
that's useful but then I have to use more lines to figure out which ephemeral port was picked up...
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.
Mostly LGTM. Some cleaning up around logging would be good, but this seems to be a pretty useful example
e9d0fc7
to
b2a5c6a
Compare
@whyrusleeping changed the logging. Thanks! |
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.
LGTM
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 <[email protected]>
b2a5c6a
to
93802a4
Compare
@whyrusleeping heads up, tests are veery happy here :) |
feat: handle no addresses
remove metadata interning
Improved echo example
Added example for multicodecs
Related to ipfs-inactive/docs#17