Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
91fec896
Unverified
Commit
91fec896
authored
7 years ago
by
Steven Allen
Committed by
GitHub
7 years ago
Browse files
Options
Download
Plain Diff
Merge pull request #291 from libp2p/fix/tests
fix CI and gx
parents
bd3e85cb
b7c2a0a9
master
2018-Q4-OKR
feat/protobuf
fix/473
fix/no-custom-field
fix/reset-ping-stream
fix/revert-correct-external-addr
gx/update-nza0mn
jenkinsfile
multistream-ping
punching
v6.0.23
v6.0.22
v6.0.21
v6.0.20
v6.0.19
v6.0.18
v6.0.17
v6.0.16
v6.0.15
v6.0.14
v6.0.13
v6.0.12
v6.0.11
v6.0.10
v6.0.9
v6.0.8
v6.0.7
v6.0.6
v6.0.5
v6.0.4
v6.0.3
v6.0.2
v6.0.1
v6.0.0
v5.0.21
v5.0.20
v5.0.19
v5.0.18
v5.0.17
v5.0.16
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/http-proxy/proxy.go
+6
-4
examples/http-proxy/proxy.go
examples/multipro/echo.go
+9
-9
examples/multipro/echo.go
with
15 additions
and
13 deletions
+15
-13
examples/http-proxy/proxy.go
View file @
91fec896
...
...
@@ -242,9 +242,7 @@ func addAddrToPeerstore(h host.Host, addr string) peer.ID {
return
peerid
}
func
main
()
{
flag
.
Usage
=
func
()
{
fmt
.
Println
(
`
const
help
=
`
This example creates a simple HTTP Proxy using two libp2p peers. The first peer
provides an HTTP server locally which tunnels the HTTP requests with libp2p
to a remote peer. The remote peer performs the requests and
...
...
@@ -256,7 +254,11 @@ Usage: Start remote peer first with: ./proxy
Then you can do something like: curl -x "localhost:9900" "http://ipfs.io".
This proxies sends the request through the local peer, which proxies it to
the remote peer, which makes it and sends the response back.
`
)
`
func
main
()
{
flag
.
Usage
=
func
()
{
fmt
.
Println
(
help
)
flag
.
PrintDefaults
()
}
...
...
This diff is collapsed.
Click to expand it.
examples/multipro/echo.go
View file @
91fec896
...
...
@@ -9,7 +9,7 @@ import (
inet
"github.com/libp2p/go-libp2p-net"
"github.com/libp2p/go-libp2p-host"
p
2p
"github.com/libp2p/go-libp2p/examples/multipro/pb"
p
b
"github.com/libp2p/go-libp2p/examples/multipro/pb"
protobufCodec
"github.com/multiformats/go-multicodec/protobuf"
uuid
"github.com/satori/go.uuid"
)
...
...
@@ -19,13 +19,13 @@ const echoRequest = "/echo/echoreq/0.0.1"
const
echoResponse
=
"/echo/echoresp/0.0.1"
type
EchoProtocol
struct
{
node
*
Node
// local host
requests
map
[
string
]
*
p
2p
.
EchoRequest
// used to access request data from response handlers
done
chan
bool
// only for demo purposes to hold main from terminating
node
*
Node
// local host
requests
map
[
string
]
*
p
b
.
EchoRequest
// used to access request data from response handlers
done
chan
bool
// only for demo purposes to hold main from terminating
}
func
NewEchoProtocol
(
node
*
Node
,
done
chan
bool
)
*
EchoProtocol
{
e
:=
EchoProtocol
{
node
:
node
,
requests
:
make
(
map
[
string
]
*
p
2p
.
EchoRequest
),
done
:
done
}
e
:=
EchoProtocol
{
node
:
node
,
requests
:
make
(
map
[
string
]
*
p
b
.
EchoRequest
),
done
:
done
}
node
.
SetStreamHandler
(
echoRequest
,
e
.
onEchoRequest
)
node
.
SetStreamHandler
(
echoResponse
,
e
.
onEchoResponse
)
...
...
@@ -38,7 +38,7 @@ func NewEchoProtocol(node *Node, done chan bool) *EchoProtocol {
// remote peer requests handler
func
(
e
*
EchoProtocol
)
onEchoRequest
(
s
inet
.
Stream
)
{
// get request data
data
:=
&
p
2p
.
EchoRequest
{}
data
:=
&
p
b
.
EchoRequest
{}
decoder
:=
protobufCodec
.
Multicodec
(
nil
)
.
Decoder
(
bufio
.
NewReader
(
s
))
err
:=
decoder
.
Decode
(
data
)
if
err
!=
nil
{
...
...
@@ -59,7 +59,7 @@ func (e *EchoProtocol) onEchoRequest(s inet.Stream) {
// send response to the request using the message string he provided
resp
:=
&
p
2p
.
EchoResponse
{
resp
:=
&
p
b
.
EchoResponse
{
MessageData
:
e
.
node
.
NewMessageData
(
data
.
MessageData
.
Id
,
false
),
Message
:
data
.
Message
}
...
...
@@ -88,7 +88,7 @@ func (e *EchoProtocol) onEchoRequest(s inet.Stream) {
// remote echo response handler
func
(
e
*
EchoProtocol
)
onEchoResponse
(
s
inet
.
Stream
)
{
data
:=
&
p
2p
.
EchoResponse
{}
data
:=
&
p
b
.
EchoResponse
{}
decoder
:=
protobufCodec
.
Multicodec
(
nil
)
.
Decoder
(
bufio
.
NewReader
(
s
))
err
:=
decoder
.
Decode
(
data
)
if
err
!=
nil
{
...
...
@@ -125,7 +125,7 @@ func (e *EchoProtocol) Echo(host host.Host) bool {
log
.
Printf
(
"%s: Sending echo to: %s...."
,
e
.
node
.
ID
(),
host
.
ID
())
// create message data
req
:=
&
p
2p
.
EchoRequest
{
req
:=
&
p
b
.
EchoRequest
{
MessageData
:
e
.
node
.
NewMessageData
(
uuid
.
Must
(
uuid
.
NewV4
())
.
String
(),
false
),
Message
:
fmt
.
Sprintf
(
"Echo from %s"
,
e
.
node
.
ID
())}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help