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 {
|
type downstreamConn struct {
|
||||||
|
id uint64
|
||||||
net net.Conn
|
net net.Conn
|
||||||
irc *irc.Conn
|
irc *irc.Conn
|
||||||
srv *Server
|
srv *Server
|
||||||
@ -85,8 +86,9 @@ type downstreamConn struct {
|
|||||||
ourMessages map[*irc.Message]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{
|
dc := &downstreamConn{
|
||||||
|
id: id,
|
||||||
net: netConn,
|
net: netConn,
|
||||||
irc: irc.NewConn(netConn),
|
irc: irc.NewConn(netConn),
|
||||||
srv: srv,
|
srv: srv,
|
||||||
|
@ -100,6 +100,7 @@ func (s *Server) getUser(name string) *user {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Serve(ln net.Listener) error {
|
func (s *Server) Serve(ln net.Listener) error {
|
||||||
|
var nextDownstreamID uint64 = 1
|
||||||
for {
|
for {
|
||||||
netConn, err := ln.Accept()
|
netConn, err := ln.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -108,7 +109,8 @@ func (s *Server) Serve(ln net.Listener) error {
|
|||||||
|
|
||||||
setKeepAlive(netConn)
|
setKeepAlive(netConn)
|
||||||
|
|
||||||
dc := newDownstreamConn(s, netConn)
|
dc := newDownstreamConn(s, netConn, nextDownstreamID)
|
||||||
|
nextDownstreamID++
|
||||||
go func() {
|
go func() {
|
||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
s.downstreamConns = append(s.downstreamConns, dc)
|
s.downstreamConns = append(s.downstreamConns, dc)
|
||||||
|
Loading…
Reference in New Issue
Block a user