net: StreamHandlerMap + protocol ids
Juan Batiz-Benet committed
Dec 16, 2014 at 06:05 UTC
f18bbde3443632159404f24295a8424c93fe1a49
2 files changed
+10
-2
net/interface.go
+9
-1
@@ -11,6 +11,12 @@ import (
11
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
12
)
13
14
+const (
15
+ ProtocolBitswap = "/ipfs/bitswap"
16
+ ProtocolDHT = "/ipfs/dht"
17
+ ProtocolDiag = "/ipfs/diagnostics"
18
+)
19
+
20
// Stream represents a bidirectional channel between two agents in
21
// the IPFS network. "agent" is as granular as desired, potentially
22
// being a "request -> reply" pair, or whole protocols.
@@ -28,6 +34,8 @@ type Stream interface {
34
// incoming streams must implement.
35
type StreamHandler func(Stream)
36
37
+type StreamHandlerMap map[string]StreamHandler
38
+
39
// Conn is a connection to a remote peer. It multiplexes streams.
40
// Usually there is no need to use a Conn directly, but it may
41
// be useful to get information about the peer on the other side:
@@ -58,7 +66,7 @@ type Conn interface {
66
// do not modify it once the network is using it.
67
type Mux struct {
68
Default StreamHandler // handles unknown protocols.
61
- Handlers map[string]StreamHandler
69
+ Handlers StreamHandlerMap
70
}
71
72
// Network is the interface IPFS uses for connecting to the world.
net/mux_test.go
+1
-1
@@ -34,7 +34,7 @@ func TestHandler(t *testing.T) {
34
}
35
}
36
37
- m := Mux{Handlers: map[string]StreamHandler{}}
37
+ m := Mux{Handlers: StreamHandlerMap{}}
38
m.Default = h("default")
39
m.Handlers["dht"] = h("bitswap")
40
// m.Handlers["ipfs"] = h("bitswap") // default!