Commit f18bbde3 authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

net: StreamHandlerMap + protocol ids

parent b039ebce
......@@ -11,6 +11,12 @@ import (
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
)
const (
ProtocolBitswap = "/ipfs/bitswap"
ProtocolDHT = "/ipfs/dht"
ProtocolDiag = "/ipfs/diagnostics"
)
// Stream represents a bidirectional channel between two agents in
// the IPFS network. "agent" is as granular as desired, potentially
// being a "request -> reply" pair, or whole protocols.
......@@ -28,6 +34,8 @@ type Stream interface {
// incoming streams must implement.
type StreamHandler func(Stream)
type StreamHandlerMap map[string]StreamHandler
// Conn is a connection to a remote peer. It multiplexes streams.
// Usually there is no need to use a Conn directly, but it may
// be useful to get information about the peer on the other side:
......@@ -58,7 +66,7 @@ type Conn interface {
// do not modify it once the network is using it.
type Mux struct {
Default StreamHandler // handles unknown protocols.
Handlers map[string]StreamHandler
Handlers StreamHandlerMap
}
// Network is the interface IPFS uses for connecting to the world.
......
......@@ -34,7 +34,7 @@ func TestHandler(t *testing.T) {
}
}
m := Mux{Handlers: map[string]StreamHandler{}}
m := Mux{Handlers: StreamHandlerMap{}}
m.Default = h("default")
m.Handlers["dht"] = h("bitswap")
// m.Handlers["ipfs"] = h("bitswap") // default!
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment