From 381e02dea9527a667f9ff9e59ec01fc26f259663 Mon Sep 17 00:00:00 2001 From: Jim Male <2423859+jimmale@users.noreply.github.com> Date: Sun, 9 Jan 2022 14:37:50 -0600 Subject: [PATCH] stuff --- listener/listener.go | 27 +++++++++++++++++++++++++++ peer/peer.go | 14 +++++++++++--- peer/peerDiscoverer.go | 2 +- 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 listener/listener.go 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 +}