File tree Expand file tree Collapse file tree 2 files changed +16
-28
lines changed Expand file tree Collapse file tree 2 files changed +16
-28
lines changed Original file line number Diff line number Diff line change 11package socks5
22
3- import (
4- "net"
5- )
6-
73// RuleSet is used to provide custom rules to allow or prohibit actions
84type RuleSet interface {
9- // AllowConnect is used to filter connect requests
10- AllowConnect (dstIP net.IP , dstPort int , srcIP net.IP , srcPort int ) bool
11-
12- // AllowBind is used to filter bind requests
13- AllowBind (dstIP net.IP , dstPort int , srcIP net.IP , srcPort int ) bool
14-
15- // AllowAssociate is used to filter associate requests
16- AllowAssociate (dstIP net.IP , dstPort int , srcIP net.IP , srcPort int ) bool
5+ Allow (req * Request ) bool
176}
187
198// PermitAll returns a RuleSet which allows all types of connections
@@ -34,14 +23,15 @@ type PermitCommand struct {
3423 EnableAssociate bool
3524}
3625
37- func (p * PermitCommand ) AllowConnect (net.IP , int , net.IP , int ) bool {
38- return p .EnableConnect
39- }
40-
41- func (p * PermitCommand ) AllowBind (net.IP , int , net.IP , int ) bool {
42- return p .EnableBind
43- }
44-
45- func (p * PermitCommand ) AllowAssociate (net.IP , int , net.IP , int ) bool {
46- return p .EnableAssociate
26+ func (p * PermitCommand ) Allow (req * Request ) bool {
27+ switch req .Command {
28+ case ConnectCommand :
29+ return p .EnableConnect
30+ case BindCommand :
31+ return p .EnableBind
32+ case AssociateCommand :
33+ return p .EnableAssociate
34+ }
35+
36+ return false
4737}
Original file line number Diff line number Diff line change 11package socks5
22
3- import (
4- "testing"
5- )
3+ import "testing"
64
75func TestPermitCommand (t * testing.T ) {
86 r := & PermitCommand {true , false , false }
97
10- if ! r .AllowConnect ( nil , 500 , nil , 1000 ) {
8+ if ! r .Allow ( & Request { Command : ConnectCommand } ) {
119 t .Fatalf ("expect connect" )
1210 }
1311
14- if r .AllowBind ( nil , 500 , nil , 1000 ) {
12+ if r .Allow ( & Request { Command : BindCommand } ) {
1513 t .Fatalf ("do not expect bind" )
1614 }
1715
18- if r .AllowAssociate ( nil , 500 , nil , 1000 ) {
16+ if r .Allow ( & Request { Command : AssociateCommand } ) {
1917 t .Fatalf ("do not expect associate" )
2018 }
2119}
You can’t perform that action at this time.
0 commit comments