diff --git a/downstream.go b/downstream.go index 9636456..f5bc48c 100644 --- a/downstream.go +++ b/downstream.go @@ -57,6 +57,7 @@ type ringMessage struct { } type downstreamConn struct { + id uint64 net net.Conn irc *irc.Conn srv *Server @@ -85,8 +86,9 @@ type downstreamConn struct { ourMessages map[*irc.Message]struct{} } -func newDownstreamConn(srv *Server, netConn net.Conn) *downstreamConn { +func newDownstreamConn(srv *Server, netConn net.Conn, id uint64) *downstreamConn { dc := &downstreamConn{ + id: id, net: netConn, irc: irc.NewConn(netConn), srv: srv, diff --git a/server.go b/server.go index 62d30da..60dfafc 100644 --- a/server.go +++ b/server.go @@ -100,6 +100,7 @@ func (s *Server) getUser(name string) *user { } func (s *Server) Serve(ln net.Listener) error { + var nextDownstreamID uint64 = 1 for { netConn, err := ln.Accept() if err != nil { @@ -108,7 +109,8 @@ func (s *Server) Serve(ln net.Listener) error { setKeepAlive(netConn) - dc := newDownstreamConn(s, netConn) + dc := newDownstreamConn(s, netConn, nextDownstreamID) + nextDownstreamID++ go func() { s.lock.Lock() s.downstreamConns = append(s.downstreamConns, dc)