WIP: duplicate / counter checking. Working well
This commit is contained in:
parent
62bf956c10
commit
a561dd3cce
16
node/conn.go
16
node/conn.go
@ -60,17 +60,21 @@ func (w *connWriter) WriteTo(remoteIP, packetType byte, data []byte) error {
|
||||
|
||||
type connReader struct {
|
||||
*net.UDPConn
|
||||
localIP byte
|
||||
counters [256]uint64
|
||||
lookup func(byte) *peer
|
||||
localIP byte
|
||||
dupChecks [256]*dupCheck
|
||||
lookup func(byte) *peer
|
||||
}
|
||||
|
||||
func newConnReader(conn *net.UDPConn, localIP byte, lookup func(byte) *peer) *connReader {
|
||||
return &connReader{
|
||||
r := &connReader{
|
||||
UDPConn: conn,
|
||||
localIP: localIP,
|
||||
lookup: lookup,
|
||||
}
|
||||
for i := range r.dupChecks {
|
||||
r.dupChecks[i] = newDupCheck(0)
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
func (r *connReader) Read(buf []byte) (remoteAddr netip.AddrPort, h header, data []byte, err error) {
|
||||
@ -94,8 +98,8 @@ func (r *connReader) Read(buf []byte) (remoteAddr netip.AddrPort, h header, data
|
||||
continue // Packet is corrupt.
|
||||
}
|
||||
|
||||
if h.Counter > r.counters[h.SourceIP] {
|
||||
r.counters[h.SourceIP] = h.Counter
|
||||
if r.dupChecks[h.SourceIP].IsDup(h.Counter) {
|
||||
continue
|
||||
}
|
||||
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user