| skipped 8 lines |
9 | 9 | | // AddUserAgents appends to the list of useragents we randomly choose from during proxied requests |
10 | 10 | | func (p5 *Swamp) AddUserAgents(uagents []string) { |
11 | 11 | | p5.mu.Lock() |
12 | | - | defer p5.mu.Unlock() |
13 | 12 | | p5.swampopt.userAgents = append(p5.swampopt.userAgents, uagents...) |
| 13 | + | p5.mu.Unlock() |
14 | 14 | | } |
15 | 15 | | |
16 | 16 | | // SetUserAgents sets the list of useragents we randomly choose from during proxied requests |
17 | 17 | | func (p5 *Swamp) SetUserAgents(uagents []string) { |
18 | 18 | | p5.mu.Lock() |
19 | | - | defer p5.mu.Unlock() |
20 | 19 | | p5.swampopt.userAgents = uagents |
| 20 | + | p5.mu.Unlock() |
21 | 21 | | } |
22 | 22 | | |
23 | 23 | | // SetCheckEndpoints replaces the running list of whatismyip style endpoitns for validation. (must return only the WAN IP) |
24 | 24 | | func (p5 *Swamp) SetCheckEndpoints(newendpoints []string) { |
25 | 25 | | p5.mu.Lock() |
26 | | - | defer p5.mu.Unlock() |
27 | 26 | | p5.swampopt.checkEndpoints = newendpoints |
| 27 | + | p5.mu.Unlock() |
28 | 28 | | } |
29 | 29 | | |
30 | 30 | | // AddCheckEndpoints appends entries to the running list of whatismyip style endpoitns for validation. (must return only the WAN IP) |
31 | 31 | | func (p5 *Swamp) AddCheckEndpoints(endpoints []string) { |
32 | 32 | | p5.mu.Lock() |
33 | | - | defer p5.mu.Unlock() |
34 | 33 | | p5.swampopt.checkEndpoints = append(p5.swampopt.checkEndpoints, endpoints...) |
| 34 | + | p5.mu.Unlock() |
35 | 35 | | } |
36 | 36 | | |
37 | 37 | | // SetStaleTime replaces the duration of time after which a proxy will be considered "stale". stale proxies will be skipped upon retrieval. |
38 | 38 | | func (p5 *Swamp) SetStaleTime(newtime time.Duration) { |
39 | 39 | | p5.swampopt.Lock() |
40 | | - | defer p5.swampopt.Unlock() |
41 | 40 | | p5.swampopt.stale = newtime |
| 41 | + | p5.swampopt.Unlock() |
42 | 42 | | } |
43 | 43 | | |
44 | 44 | | // SetValidationTimeout sets the validationTimeout option. |
45 | 45 | | func (p5 *Swamp) SetValidationTimeout(timeout time.Duration) { |
46 | 46 | | p5.swampopt.Lock() |
47 | | - | defer p5.swampopt.Unlock() |
48 | 47 | | p5.swampopt.validationTimeout = timeout |
| 48 | + | p5.swampopt.Unlock() |
49 | 49 | | } |
50 | 50 | | |
51 | 51 | | // SetServerTimeout sets the serverTimeout option. |
| skipped 1 lines |
53 | 53 | | // * To disable timeout on outgoing MysteryDialer connections, set this to time.Duration(0). |
54 | 54 | | func (p5 *Swamp) SetServerTimeout(timeout time.Duration) { |
55 | 55 | | p5.swampopt.Lock() |
56 | | - | defer p5.swampopt.Unlock() |
57 | 56 | | p5.swampopt.serverTimeout = timeout |
| 57 | + | p5.swampopt.Unlock() |
58 | 58 | | } |
59 | 59 | | |
60 | 60 | | // SetMaxWorkers set the maximum workers for proxy checking and clears the current proxy map and worker pool jobs. |
| skipped 4 lines |
65 | 65 | | // EnableRecycling enables recycling used proxies back into the pending channel for revalidation after dispensed. |
66 | 66 | | func (p5 *Swamp) EnableRecycling() { |
67 | 67 | | p5.swampopt.Lock() |
68 | | - | defer p5.swampopt.Unlock() |
69 | 68 | | p5.swampopt.recycle = true |
| 69 | + | p5.swampopt.Unlock() |
70 | 70 | | } |
71 | 71 | | |
72 | 72 | | // DisableRecycling disables recycling used proxies back into the pending channel for revalidation after dispensed. |
73 | 73 | | func (p5 *Swamp) DisableRecycling() { |
74 | 74 | | p5.swampopt.Lock() |
75 | | - | defer p5.swampopt.Unlock() |
76 | 75 | | p5.swampopt.recycle = false |
| 76 | + | p5.swampopt.Unlock() |
77 | 77 | | } |
78 | 78 | | |
79 | 79 | | // SetRemoveAfter sets the removeafter policy, the amount of times a recycled proxy is marked as bad before it is removed entirely. |
| skipped 2 lines |
82 | 82 | | // - Only applies when recycling is enabled |
83 | 83 | | func (p5 *Swamp) SetRemoveAfter(timesfailed int) { |
84 | 84 | | p5.swampopt.Lock() |
85 | | - | defer p5.swampopt.Unlock() |
86 | 85 | | p5.swampopt.removeafter = timesfailed |
| 86 | + | p5.swampopt.Unlock() |
87 | 87 | | } |
88 | 88 | | |
89 | 89 | | // SetDialerBailout sets the amount of times the MysteryDialer will dial out and fail before it bails out. |
90 | 90 | | // - The dialer will attempt to redial a destination with a different proxy a specified amount of times before it gives up |
91 | 91 | | func (p5 *Swamp) SetDialerBailout(dialattempts int) { |
92 | 92 | | p5.swampopt.Lock() |
93 | | - | defer p5.swampopt.Unlock() |
94 | 93 | | p5.swampopt.dialerBailout = dialattempts |
| 94 | + | p5.swampopt.Unlock() |
95 | 95 | | } |
96 | 96 | | |
97 | 97 | | // SetDispenseMiddleware will add a function that sits within the dialing process of the MysteryDialer and anyhing using it. |
| skipped 1 lines |
99 | 99 | | // Take care modiying the proxy in-flight as it is a pointer. |
100 | 100 | | func (p5 *Swamp) SetDispenseMiddleware(f func(*Proxy) (*Proxy, bool)) { |
101 | 101 | | p5.mu.Lock() |
102 | | - | defer p5.mu.Unlock() |
103 | 102 | | p5.dispenseMiddleware = f |
| 103 | + | p5.mu.Unlock() |
104 | 104 | | } |
105 | 105 | | |
106 | 106 | | // SetDebugLogger sets the debug logger for the Swamp. See the Logger interface for implementation details. |
| skipped 6 lines |
113 | 113 | | } |
114 | 114 | | |
115 | 115 | | func (p5 *Swamp) SetShuffle(shuffle bool) { |
116 | | - | p5.mu.Lock() |
117 | | - | defer p5.mu.Unlock() |
| 116 | + | p5.swampopt.Lock() |
118 | 117 | | p5.swampopt.shuffle = shuffle |
| 118 | + | p5.swampopt.Unlock() |
119 | 119 | | } |
120 | 120 | | |