Created
September 15, 2013 21:09
-
-
Save arlolra/6574344 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/check/datastore.go b/src/check/datastore.go | |
index fb7b08d..8091319 100644 | |
--- a/src/check/datastore.go | |
+++ b/src/check/datastore.go | |
@@ -8,7 +8,6 @@ import ( | |
"net" | |
"os" | |
"os/signal" | |
- "sort" | |
"syscall" | |
"time" | |
) | |
@@ -29,28 +28,39 @@ type Exits struct { | |
TorIPs map[string]bool | |
} | |
+type Thing struct { | |
+ Order int | |
+ IsAccept bool | |
+ Output []byte | |
+} | |
+ | |
func (e *Exits) IsAllowed(address net.IP, port int, cb func([]byte)) { | |
rules, err := e.List.Intersect(uint16(port)) | |
if err != nil { | |
return | |
} | |
- sort.Sort(OrderedRuleIntervalSlice(rules)) | |
- | |
- // sorted rules are ordered by Policy.Id (ascending) | |
- lastPolicyResult := -1 | |
+ output := make(map[int]Thing) | |
for _, i := range rules { | |
r := i.Tag.(*Rule) | |
- if lastPolicyResult >= r.ParentPolicy.Id { | |
+ out, ok := output[r.ParentPolicy.Id] | |
+ if ok && r.Order > out.Order { | |
continue | |
} | |
if r.IsMatch(address) { | |
- lastPolicyResult = r.ParentPolicy.Id | |
- if r.IsAccept { | |
- cb(r.ParentPolicy.AddressNewLine) | |
+ output[r.ParentPolicy.Id] = Thing{ | |
+ r.Order, | |
+ r.IsAccept, | |
+ r.ParentPolicy.AddressNewLine, | |
} | |
} | |
} | |
+ | |
+ for _, r := range output { | |
+ if r.IsAccept { | |
+ cb(r.Output) | |
+ } | |
+ } | |
} | |
func (e *Exits) Dump(w io.Writer, ip string, port int) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment