remove OpenedStream and ClosedStream from Notifiee interface (#250)
* remove TODO for PeerConnected and PeerDisconnected from Notifiee This is now done via the event bus. * remove OpenedStream and ClosedStream from Notifiee
This commit is contained in:
parent
4e29e4044f
commit
48ba07f29e
|
@ -11,12 +11,6 @@ type Notifiee interface {
|
||||||
ListenClose(Network, ma.Multiaddr) // called when network stops listening on an addr
|
ListenClose(Network, ma.Multiaddr) // called when network stops listening on an addr
|
||||||
Connected(Network, Conn) // called when a connection opened
|
Connected(Network, Conn) // called when a connection opened
|
||||||
Disconnected(Network, Conn) // called when a connection closed
|
Disconnected(Network, Conn) // called when a connection closed
|
||||||
OpenedStream(Network, Stream) // called when a stream opened
|
|
||||||
ClosedStream(Network, Stream) // called when a stream closed
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
// PeerConnected(Network, peer.ID) // called when a peer connected
|
|
||||||
// PeerDisconnected(Network, peer.ID) // called when a peer disconnected
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NotifyBundle implements Notifiee by calling any of the functions set on it,
|
// NotifyBundle implements Notifiee by calling any of the functions set on it,
|
||||||
|
@ -28,9 +22,6 @@ type NotifyBundle struct {
|
||||||
|
|
||||||
ConnectedF func(Network, Conn)
|
ConnectedF func(Network, Conn)
|
||||||
DisconnectedF func(Network, Conn)
|
DisconnectedF func(Network, Conn)
|
||||||
|
|
||||||
OpenedStreamF func(Network, Stream)
|
|
||||||
ClosedStreamF func(Network, Stream)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Notifiee = (*NotifyBundle)(nil)
|
var _ Notifiee = (*NotifyBundle)(nil)
|
||||||
|
@ -63,20 +54,6 @@ func (nb *NotifyBundle) Disconnected(n Network, c Conn) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenedStream calls OpenedStreamF if it is not null.
|
|
||||||
func (nb *NotifyBundle) OpenedStream(n Network, s Stream) {
|
|
||||||
if nb.OpenedStreamF != nil {
|
|
||||||
nb.OpenedStreamF(n, s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClosedStream calls ClosedStreamF if it is not null.
|
|
||||||
func (nb *NotifyBundle) ClosedStream(n Network, s Stream) {
|
|
||||||
if nb.ClosedStreamF != nil {
|
|
||||||
nb.ClosedStreamF(n, s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Global noop notifiee. Do not change.
|
// Global noop notifiee. Do not change.
|
||||||
var GlobalNoopNotifiee = &NoopNotifiee{}
|
var GlobalNoopNotifiee = &NoopNotifiee{}
|
||||||
|
|
||||||
|
@ -88,5 +65,3 @@ func (nn *NoopNotifiee) Connected(n Network, c Conn) {}
|
||||||
func (nn *NoopNotifiee) Disconnected(n Network, c Conn) {}
|
func (nn *NoopNotifiee) Disconnected(n Network, c Conn) {}
|
||||||
func (nn *NoopNotifiee) Listen(n Network, addr ma.Multiaddr) {}
|
func (nn *NoopNotifiee) Listen(n Network, addr ma.Multiaddr) {}
|
||||||
func (nn *NoopNotifiee) ListenClose(n Network, addr ma.Multiaddr) {}
|
func (nn *NoopNotifiee) ListenClose(n Network, addr ma.Multiaddr) {}
|
||||||
func (nn *NoopNotifiee) OpenedStream(Network, Stream) {}
|
|
||||||
func (nn *NoopNotifiee) ClosedStream(Network, Stream) {}
|
|
||||||
|
|
|
@ -85,39 +85,3 @@ func TestDisconnected(T *testing.T) {
|
||||||
T.Fatal("Disconnected should have been called")
|
T.Fatal("Disconnected should have been called")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOpenedStream(T *testing.T) {
|
|
||||||
var notifee NotifyBundle
|
|
||||||
notifee.OpenedStream(nil, nil)
|
|
||||||
|
|
||||||
called := false
|
|
||||||
notifee.OpenedStreamF = func(Network, Stream) {
|
|
||||||
called = true
|
|
||||||
}
|
|
||||||
if called {
|
|
||||||
T.Fatal("called should be false")
|
|
||||||
}
|
|
||||||
|
|
||||||
notifee.OpenedStream(nil, nil)
|
|
||||||
if !called {
|
|
||||||
T.Fatal("OpenedStream should have been called")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestClosedStream(T *testing.T) {
|
|
||||||
var notifee NotifyBundle
|
|
||||||
notifee.ClosedStream(nil, nil)
|
|
||||||
|
|
||||||
called := false
|
|
||||||
notifee.ClosedStreamF = func(Network, Stream) {
|
|
||||||
called = true
|
|
||||||
}
|
|
||||||
if called {
|
|
||||||
T.Fatal("called should be false")
|
|
||||||
}
|
|
||||||
|
|
||||||
notifee.ClosedStream(nil, nil)
|
|
||||||
if !called {
|
|
||||||
T.Fatal("ClosedStream should have been called")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue