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-dms3
Commits
2309266f
Commit
2309266f
authored
10 years ago
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow removal of stream handlers
parent
03c0b2d3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
0 deletions
+27
-0
p2p/host/basic/basic_host.go
p2p/host/basic/basic_host.go
+4
-0
p2p/host/host.go
p2p/host/host.go
+4
-0
p2p/host/routed/routed.go
p2p/host/routed/routed.go
+10
-0
p2p/protocol/mux.go
p2p/protocol/mux.go
+9
-0
No files found.
p2p/host/basic/basic_host.go
View file @
2309266f
...
...
@@ -118,6 +118,10 @@ func (h *BasicHost) SetStreamHandler(pid protocol.ID, handler inet.StreamHandler
h
.
Mux
()
.
SetHandler
(
pid
,
handler
)
}
func
(
h
*
BasicHost
)
RemoveStreamHandler
(
pid
protocol
.
ID
)
{
h
.
Mux
()
.
RemoveHandler
(
pid
)
}
// NewStream opens a new stream to given peer p, and writes a p2p/protocol
// header with given protocol.ID. If there is no connection to p, attempts
// to create one. If ProtocolID is "", writes no header.
...
...
This diff is collapsed.
Click to expand it.
p2p/host/host.go
View file @
2309266f
...
...
@@ -46,6 +46,10 @@ type Host interface {
// (Threadsafe)
SetStreamHandler
(
pid
protocol
.
ID
,
handler
inet
.
StreamHandler
)
// RemoveStreamHandler removes a handler on the mux that was set by
// SetStreamHandler
RemoveStreamHandler
(
pid
protocol
.
ID
)
// NewStream opens a new stream to given peer p, and writes a p2p/protocol
// header with given protocol.ID. If there is no connection to p, attempts
// to create one. If ProtocolID is "", writes no header.
...
...
This diff is collapsed.
Click to expand it.
p2p/host/routed/routed.go
View file @
2309266f
...
...
@@ -84,21 +84,31 @@ func logRoutingErrDifferentPeers(ctx context.Context, wanted, got peer.ID, err e
func
(
rh
*
RoutedHost
)
ID
()
peer
.
ID
{
return
rh
.
host
.
ID
()
}
func
(
rh
*
RoutedHost
)
Peerstore
()
peer
.
Peerstore
{
return
rh
.
host
.
Peerstore
()
}
func
(
rh
*
RoutedHost
)
Addrs
()
[]
ma
.
Multiaddr
{
return
rh
.
host
.
Addrs
()
}
func
(
rh
*
RoutedHost
)
Network
()
inet
.
Network
{
return
rh
.
host
.
Network
()
}
func
(
rh
*
RoutedHost
)
Mux
()
*
protocol
.
Mux
{
return
rh
.
host
.
Mux
()
}
func
(
rh
*
RoutedHost
)
SetStreamHandler
(
pid
protocol
.
ID
,
handler
inet
.
StreamHandler
)
{
rh
.
host
.
SetStreamHandler
(
pid
,
handler
)
}
func
(
rh
*
RoutedHost
)
RemoveStreamHandler
(
pid
protocol
.
ID
)
{
rh
.
host
.
RemoveStreamHandler
(
pid
)
}
func
(
rh
*
RoutedHost
)
NewStream
(
pid
protocol
.
ID
,
p
peer
.
ID
)
(
inet
.
Stream
,
error
)
{
return
rh
.
host
.
NewStream
(
pid
,
p
)
}
...
...
This diff is collapsed.
Click to expand it.
p2p/protocol/mux.go
View file @
2309266f
...
...
@@ -90,6 +90,15 @@ func (m *Mux) SetHandler(p ID, h inet.StreamHandler) {
m
.
lock
.
Unlock
()
}
// RemoveHandler removes the protocol handler on the Network's Muxer.
// This operation is threadsafe.
func
(
m
*
Mux
)
RemoveHandler
(
p
ID
)
{
log
.
Debugf
(
"%s removing handler for protocol: %s (%d)"
,
m
,
p
,
len
(
p
))
m
.
lock
.
Lock
()
delete
(
m
.
handlers
,
p
)
m
.
lock
.
Unlock
()
}
// Handle reads the next name off the Stream, and calls a handler function
// This is done in its own goroutine, to avoid blocking the caller.
func
(
m
*
Mux
)
Handle
(
s
inet
.
Stream
)
{
...
...
This diff is collapsed.
Click to expand it.
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