From cb70ed707ddfe52362fd3c60f6ca509be952583b Mon Sep 17 00:00:00 2001 From: Meloneat <3318004856@qq.com> Date: Sat, 29 Feb 2020 22:50:53 +0800 Subject: [PATCH 1/5] Avoid confusing the event definition of stream --- http-proxy/proxy.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/http-proxy/proxy.go b/http-proxy/proxy.go index 8c25627..7a96870 100644 --- a/http-proxy/proxy.go +++ b/http-proxy/proxy.go @@ -60,9 +60,13 @@ func NewProxyService(h host.Host, proxyAddr ma.Multiaddr, dest peer.ID) *ProxySe // We let our host know that it needs to handle streams tagged with the // protocol id that we have defined, and then handle them to // our own streamHandling function. - h.SetStreamHandler(Protocol, streamHandler) + ps := "Proxy" + if len(dest) == 0 { + h.SetStreamHandler(Protocol, streamHandler) + ps = "Remote Peer" + } - fmt.Println("Proxy server is ready") + fmt.Printf("%s server is rfeady", ps) fmt.Println("libp2p-peer addresses:") for _, a := range h.Addrs() { fmt.Printf("%s/ipfs/%s\n", a, peer.IDB58Encode(h.ID())) From 1ee7267db888d49a34428110dc6f75480696edf9 Mon Sep 17 00:00:00 2001 From: Meloneat <3318004856@qq.com> Date: Sat, 29 Feb 2020 23:10:18 +0800 Subject: [PATCH 2/5] Sample fix --- http-proxy/proxy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/http-proxy/proxy.go b/http-proxy/proxy.go index 7a96870..0dea882 100644 --- a/http-proxy/proxy.go +++ b/http-proxy/proxy.go @@ -66,7 +66,7 @@ func NewProxyService(h host.Host, proxyAddr ma.Multiaddr, dest peer.ID) *ProxySe ps = "Remote Peer" } - fmt.Printf("%s server is rfeady", ps) + fmt.Printf("%s server is ready", ps) fmt.Println("libp2p-peer addresses:") for _, a := range h.Addrs() { fmt.Printf("%s/ipfs/%s\n", a, peer.IDB58Encode(h.ID())) From 5e2861f8762d6e35df7cd2297692e3719caab9be Mon Sep 17 00:00:00 2001 From: Meloneat <3318004856@qq.com> Date: Sat, 29 Feb 2020 23:25:55 +0800 Subject: [PATCH 3/5] Reback --- http-proxy/proxy.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/http-proxy/proxy.go b/http-proxy/proxy.go index 0dea882..f4a9732 100644 --- a/http-proxy/proxy.go +++ b/http-proxy/proxy.go @@ -60,13 +60,16 @@ func NewProxyService(h host.Host, proxyAddr ma.Multiaddr, dest peer.ID) *ProxySe // We let our host know that it needs to handle streams tagged with the // protocol id that we have defined, and then handle them to // our own streamHandling function. - ps := "Proxy" - if len(dest) == 0 { - h.SetStreamHandler(Protocol, streamHandler) - ps = "Remote Peer" - } + // ps := "Proxy" + // if len(dest) == 0 { + // h.SetStreamHandler(Protocol, streamHandler) + // ps = "Remote Peer" + // } + + // fmt.Printf("%s server is ready", ps) - fmt.Printf("%s server is ready", ps) + h.SetStreamHandler(Protocol, streamHandler) + fmt.Println("Proxy server is ready") fmt.Println("libp2p-peer addresses:") for _, a := range h.Addrs() { fmt.Printf("%s/ipfs/%s\n", a, peer.IDB58Encode(h.ID())) From 4f253ab494857b674f0b3801457cf4dd83a0420d Mon Sep 17 00:00:00 2001 From: Meloneat <3318004856@qq.com> Date: Sat, 29 Feb 2020 23:37:36 +0800 Subject: [PATCH 4/5] dismiss whitespace --- http-proxy/proxy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/http-proxy/proxy.go b/http-proxy/proxy.go index f4a9732..45ae4d5 100644 --- a/http-proxy/proxy.go +++ b/http-proxy/proxy.go @@ -63,7 +63,7 @@ func NewProxyService(h host.Host, proxyAddr ma.Multiaddr, dest peer.ID) *ProxySe // ps := "Proxy" // if len(dest) == 0 { // h.SetStreamHandler(Protocol, streamHandler) - // ps = "Remote Peer" + // ps = "Remote Peer" // } // fmt.Printf("%s server is ready", ps) From ae998c5f9135853e23187bfea3cdd3d206136125 Mon Sep 17 00:00:00 2001 From: Meloneat <3318004856@qq.com> Date: Sat, 29 Feb 2020 23:45:28 +0800 Subject: [PATCH 5/5] Avoid confusing the event definition of stream --- http-proxy/proxy.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/http-proxy/proxy.go b/http-proxy/proxy.go index 45ae4d5..88c0e72 100644 --- a/http-proxy/proxy.go +++ b/http-proxy/proxy.go @@ -60,16 +60,13 @@ func NewProxyService(h host.Host, proxyAddr ma.Multiaddr, dest peer.ID) *ProxySe // We let our host know that it needs to handle streams tagged with the // protocol id that we have defined, and then handle them to // our own streamHandling function. - // ps := "Proxy" - // if len(dest) == 0 { - // h.SetStreamHandler(Protocol, streamHandler) - // ps = "Remote Peer" - // } - - // fmt.Printf("%s server is ready", ps) + ps := "Proxy" + if len(dest) == 0 { + h.SetStreamHandler(Protocol, streamHandler) + ps = "Remote Peer" + } - h.SetStreamHandler(Protocol, streamHandler) - fmt.Println("Proxy server is ready") + fmt.Printf("%s server is ready", ps) fmt.Println("libp2p-peer addresses:") for _, a := range h.Addrs() { fmt.Printf("%s/ipfs/%s\n", a, peer.IDB58Encode(h.ID()))