p2p: fix some stuff after refactor
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
Łukasz Magiera committed
May 22, 2018 at 14:35 UTC
cf6ddcbf70cf2a963a90b89281540ad2825935fb
4 files changed
+24
-18
p2p/inbound.go
+4
@@ -16,13 +16,17 @@ type inboundListener struct {
16
// Application proto identifier.
17
proto string
18
19
+ // Address to proxy the incoming connections to
20
addr ma.Multiaddr
21
}
22
23
// NewListener creates new p2p listener
24
func (p2p *P2P) NewListener(ctx context.Context, proto string, addr ma.Multiaddr) (Listener, error) {
25
listenerInfo := &inboundListener{
26
+ p2p: p2p,
27
+
28
proto: proto,
29
+ addr: addr,
30
}
31
32
p2p.peerHost.SetStreamHandler(protocol.ID(proto), func(remote net.Stream) {
p2p/listener.go
-15
@@ -1,11 +1,5 @@
1
package p2p
2
3
-import (
4
- pstore "gx/ipfs/QmZb7hAgQEhW9dBbzBudU39gCeD4zbe6xafD52LUuF4cUN/go-libp2p-peerstore"
5
- peer "gx/ipfs/QmcJukH2sAFjY3HdBKq35WDzWoL3UUu2gt9wdfqZTUyM74/go-libp2p-peer"
6
- p2phost "gx/ipfs/QmdHyfNVTZ5VtUx4Xz23z8wtnioSrFQ28XSfpVkdhQBkGA/go-libp2p-host"
7
-)
8
-
3
type Listener interface {
4
Protocol() string
5
Address() string
@@ -14,15 +8,6 @@ type Listener interface {
8
Close() error
9
}
10
17
-// NewP2P creates new P2P struct
18
-func NewP2P(identity peer.ID, peerHost p2phost.Host, peerstore pstore.Peerstore) *P2P {
19
- return &P2P{
20
- identity: identity,
21
- peerHost: peerHost,
22
- peerstore: peerstore,
23
- }
24
-}
25
-
11
// ListenerRegistry is a collection of local application proto listeners.
12
type ListenerRegistry struct {
13
Listeners map[string]Listener
p2p/outbound.go
+4
-3
@@ -12,10 +12,9 @@ import (
12
peer "gx/ipfs/QmcJukH2sAFjY3HdBKq35WDzWoL3UUu2gt9wdfqZTUyM74/go-libp2p-peer"
13
)
14
15
-// inboundListener accepts libp2p streams and proxies them to a manet host
15
+// outboundListener accepts libp2p streams and proxies them to a manet host
16
type outboundListener struct {
17
- ctx context.Context
18
- cancel context.CancelFunc
17
+ ctx context.Context
18
19
p2p *P2P
20
id peer.ID
@@ -34,6 +33,8 @@ func (p2p *P2P) Dial(ctx context.Context, peer peer.ID, proto string, bindAddr m
33
}
34
35
listener := &outboundListener{
36
+ ctx: ctx,
37
+
38
p2p: p2p,
39
id: p2p.identity,
40
p2p/p2p.go
+16
@@ -16,6 +16,22 @@ type P2P struct {
16
peerstore pstore.Peerstore
17
}
18
19
+// NewP2P creates new P2P struct
20
+func NewP2P(identity peer.ID, peerHost p2phost.Host, peerstore pstore.Peerstore) *P2P {
21
+ return &P2P{
22
+ identity: identity,
23
+ peerHost: peerHost,
24
+ peerstore: peerstore,
25
+
26
+ Listeners: ListenerRegistry{
27
+ Listeners: map[string]Listener{},
28
+ },
29
+ Streams: StreamRegistry{
30
+ Streams: map[uint64]*Stream{},
31
+ },
32
+ }
33
+}
34
+
35
// CheckProtoExists checks whether a proto handler is registered to
36
// mux handler
37
func (p2p *P2P) CheckProtoExists(proto string) bool {