Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
423fb0fc55 |
@@ -105,7 +105,24 @@ func (h *PrefixHandler) HandleMessage(msg *ristypes.RISMessage) {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
|
||||
// Process announcements
|
||||
// Withdrawals are queued before announcements, because the batch keeps
|
||||
// each peer's last update for a prefix: a message that lists a prefix as
|
||||
// both withdrawn and announced keeps the route (RFC 4271 section 4.3).
|
||||
for _, prefix := range msg.Withdrawals {
|
||||
h.batch = append(h.batch, prefixUpdate{
|
||||
prefix: canonicalPrefix(prefix),
|
||||
originASN: originASN, // Use the originASN from path if available
|
||||
peer: msg.Peer,
|
||||
messageType: "withdrawal",
|
||||
timestamp: timestamp,
|
||||
path: msg.Path,
|
||||
})
|
||||
// Record withdrawal in metrics
|
||||
if h.metrics != nil {
|
||||
h.metrics.RecordWithdrawal()
|
||||
}
|
||||
}
|
||||
|
||||
for _, announcement := range msg.Announcements {
|
||||
for _, prefix := range announcement.Prefixes {
|
||||
h.batch = append(h.batch, prefixUpdate{
|
||||
@@ -123,22 +140,6 @@ func (h *PrefixHandler) HandleMessage(msg *ristypes.RISMessage) {
|
||||
}
|
||||
}
|
||||
|
||||
// Process withdrawals
|
||||
for _, prefix := range msg.Withdrawals {
|
||||
h.batch = append(h.batch, prefixUpdate{
|
||||
prefix: canonicalPrefix(prefix),
|
||||
originASN: originASN, // Use the originASN from path if available
|
||||
peer: msg.Peer,
|
||||
messageType: "withdrawal",
|
||||
timestamp: timestamp,
|
||||
path: msg.Path,
|
||||
})
|
||||
// Record withdrawal in metrics
|
||||
if h.metrics != nil {
|
||||
h.metrics.RecordWithdrawal()
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we need to flush
|
||||
if len(h.batch) >= prefixBatchSize {
|
||||
h.flushBatchLocked()
|
||||
|
||||
@@ -100,6 +100,12 @@ func TestPrefixHandlerAppliesEachPeersLastUpdateInABatch(t *testing.T) {
|
||||
withdraw := func(peer string) *ristypes.RISMessage {
|
||||
return &ristypes.RISMessage{Peer: peer, ParsedTimestamp: ts, Withdrawals: []string{prefix}}
|
||||
}
|
||||
announceAndWithdraw := func(peer string) *ristypes.RISMessage {
|
||||
msg := announce(peer)
|
||||
msg.Withdrawals = []string{prefix}
|
||||
|
||||
return msg
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -133,6 +139,15 @@ func TestPrefixHandlerAppliesEachPeersLastUpdateInABatch(t *testing.T) {
|
||||
},
|
||||
wantPeers: []string{testPeerIP},
|
||||
},
|
||||
{
|
||||
// RFC 4271 section 4.3: the announcement counts, not the withdrawal.
|
||||
name: "one message announces and withdraws the prefix",
|
||||
batches: [][]*ristypes.RISMessage{
|
||||
{announce(testPeerIP)},
|
||||
{announceAndWithdraw(testPeerIP)},
|
||||
},
|
||||
wantPeers: []string{testPeerIP},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
Reference in New Issue
Block a user