diff --git a/listener/listener.go b/listener/listener.go new file mode 100644 index 0000000..1cdd3f2 --- /dev/null +++ b/listener/listener.go @@ -0,0 +1,27 @@ +package listener + +import "github.com/lucas-clemente/quic-go" + +// Singleton Pattern +var currentListener *Listener + +func GetListener() *Listener { + if currentListener == nil { + currentListener = newListener() + } + return currentListener +} + +type Listener struct { + qListener quic.Listener +} + +func newListener() *Listener { + return nil // TODO +} + +func (l *Listener) Close() { + + l.qListener.Close() + currentListener = nil +} diff --git a/peer/peer.go b/peer/peer.go index 4bbcdc9..8879351 100644 --- a/peer/peer.go +++ b/peer/peer.go @@ -1,13 +1,21 @@ package peer -import "net" -import "github.com/lucas-clemente/quic-go" +import ( + "github.com/lucas-clemente/quic-go" + log "github.com/sirupsen/logrus" + "net" +) type Peer struct { Session quic.Session } -func Connect(ip net.IP, port uint) (*Peer, error) { +func (p *Peer) Disconnect() error { + log.Tracef("Disconnecting from %s", p.Session.RemoteAddr().String()) + return p.Session.CloseWithError(0, "none") +} +func Connect(ip net.IP, port uint) (*Peer, error) { + log.Tracef("Connecting to %s:%d", ip.String(), port) return nil, nil } diff --git a/peer/peerDiscoverer.go b/peer/peerDiscoverer.go index c992cd1..e09fa47 100644 --- a/peer/peerDiscoverer.go +++ b/peer/peerDiscoverer.go @@ -9,4 +9,4 @@ type PeerDiscoverer interface { type PeerConnectionInfo struct { Address net.IP Port uint -} \ No newline at end of file +}