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:
parent
df8bfb75f2
commit
d0917f0fa1
@ -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,
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user