Skip to content

Commit

Permalink
Cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Jun 2, 2022
1 parent e4d76a4 commit a898f41
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 15 deletions.
6 changes: 3 additions & 3 deletions shadowaead_2022/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,11 +566,11 @@ func (c *clientPacketConn) ReadPacket(buffer *buf.Buffer) (M.Socksaddr, error) {
}

if sessionId == c.session.remoteSessionId {
if !c.session.filter.ValidateCounter(packetId, math.MaxUint64) {
if !c.session.filter.ValidateCounter(packetId) {
return M.Socksaddr{}, ErrPacketIdNotUnique
}
} else if sessionId == c.session.lastRemoteSessionId {
if !c.session.lastFilter.ValidateCounter(packetId, math.MaxUint64) {
if !c.session.lastFilter.ValidateCounter(packetId) {
return M.Socksaddr{}, ErrPacketIdNotUnique
}
remoteCipher = c.session.lastRemoteCipher
Expand All @@ -589,7 +589,7 @@ func (c *clientPacketConn) ReadPacket(buffer *buf.Buffer) (M.Socksaddr, error) {
}
c.session.remoteSessionId = sessionId
c.session.remoteCipher = remoteCipher
c.session.filter.ValidateCounter(packetId, math.MaxUint64)
c.session.filter.ValidateCounter(packetId)
}

var clientSessionId uint64
Expand Down
2 changes: 1 addition & 1 deletion shadowaead_2022/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ returnErr:
return err

process:
if !session.filter.ValidateCounter(packetId, math.MaxUint64) {
if !session.filter.ValidateCounter(packetId) {
err = ErrPacketIdNotUnique
goto returnErr
}
Expand Down
2 changes: 1 addition & 1 deletion shadowaead_2022/service_multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ returnErr:
return err

process:
if !session.filter.ValidateCounter(packetId, math.MaxUint64) {
if !session.filter.ValidateCounter(packetId) {
err = ErrPacketIdNotUnique
goto returnErr
}
Expand Down
11 changes: 1 addition & 10 deletions shadowaead_2022/wg_replay/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,9 @@ type Filter struct {
ring [ringBlocks]block
}

// Reset resets the filter to empty state.
func (f *Filter) Reset() {
f.last = 0
f.ring[0] = 0
}

// ValidateCounter checks if the counter should be accepted.
// Overlimit counters (>= limit) are always rejected.
func (f *Filter) ValidateCounter(counter, limit uint64) bool {
if counter >= limit {
return false
}
func (f *Filter) ValidateCounter(counter uint64) bool {
indexBlock := counter >> blockBitLog
if counter > f.last { // move window forward
current := f.last >> blockBitLog
Expand Down

0 comments on commit a898f41

Please # to comment.