Add a server-unique id to each downstream

Adding a simple uint64 id to each downstream is preparatory work
for labeled-responses tags targeting a specific downstream.
This commit is contained in:
delthas 2020-03-23 03:18:54 +01:00 committed by Simon Ser
parent df8bfb75f2
commit d0917f0fa1
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 6 additions and 2 deletions

View File

@ -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,

View File

@ -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)