Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-unixfs
Commits
c341df0a
Commit
c341df0a
authored
Jan 14, 2015
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(mux) expose method to SetDefaultHandler
parent
2678795d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
6 deletions
+12
-6
p2p/protocol/mux.go
p2p/protocol/mux.go
+11
-5
p2p/protocol/mux_test.go
p2p/protocol/mux_test.go
+1
-1
No files found.
p2p/protocol/mux.go
View file @
c341df0a
...
...
@@ -24,8 +24,8 @@ type streamHandlerMap map[ID]inet.StreamHandler
// It contains the handlers for each protocol accepted.
// It dispatches handlers for streams opened by remote peers.
type
Mux
struct
{
//
D
efault handles unknown protocols. Callers modify at your own risk.
D
efault
inet
.
StreamHandler
//
d
efault
Handler
handles unknown protocols. Callers modify at your own risk.
d
efault
Handler
inet
.
StreamHandler
lock
sync
.
RWMutex
handlers
streamHandlerMap
...
...
@@ -63,9 +63,9 @@ func (m *Mux) readHeader(s io.Reader) (ID, inet.StreamHandler, error) {
m
.
lock
.
RUnlock
()
switch
{
case
!
found
&&
m
.
D
efault
!=
nil
:
return
p
,
m
.
D
efault
,
nil
case
!
found
&&
m
.
D
efault
==
nil
:
case
!
found
&&
m
.
d
efault
Handler
!=
nil
:
return
p
,
m
.
d
efault
Handler
,
nil
case
!
found
&&
m
.
d
efault
Handler
==
nil
:
return
p
,
nil
,
fmt
.
Errorf
(
"%s no handler with name: %s (%d)"
,
m
,
p
,
len
(
p
))
default
:
return
p
,
h
,
nil
...
...
@@ -79,6 +79,12 @@ func (m *Mux) String() string {
return
fmt
.
Sprintf
(
"<Muxer %p %d>"
,
m
,
len
(
m
.
handlers
))
}
func
(
m
*
Mux
)
SetDefaultHandler
(
h
inet
.
StreamHandler
)
{
m
.
lock
.
Lock
()
m
.
defaultHandler
=
h
m
.
lock
.
Unlock
()
}
// SetHandler sets the protocol handler on the Network's Muxer.
// This operation is threadsafe.
func
(
m
*
Mux
)
SetHandler
(
p
ID
,
h
inet
.
StreamHandler
)
{
...
...
p2p/protocol/mux_test.go
View file @
c341df0a
...
...
@@ -39,7 +39,7 @@ func TestHandler(t *testing.T) {
}
m
:=
NewMux
()
m
.
Default
=
h
(
"default"
)
m
.
Set
Default
Handler
(
h
(
"default"
)
)
m
.
SetHandler
(
"/dht"
,
h
(
"bitswap"
))
// m.Handlers["/ipfs"] = h("bitswap") // default!
m
.
SetHandler
(
"/bitswap"
,
h
(
"bitswap"
))
...
...
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