Browse Source

Fixed a typo in the squid external acl helper.
Fixed the verdict and weight when there are no peers at all to 100 * 1024 instead of 0.

Eliezer Croitoru 1 year ago
parent
commit
1d0c9492fe
2 changed files with 20 additions and 2 deletions
  1. 1 1
      examples-multiple-peers/squid-external-acl-by-url.go
  2. 19 1
      peersarray.go

+ 1 - 1
examples-multiple-peers/squid-external-acl-by-url.go

@@ -46,7 +46,7 @@ func main() {
 	flag.IntVar(&blockWeight, "block-weight", 128, "Peers blacklist weight")
 	flag.IntVar(&timeout, "query-timeout", 30, "Timeout for all peers response")
 	flag.BoolVar(&debug, "debug", false, "Run in debug mode")
-	flag.BoolVar(&feederMode, "fedder-mode", false, "Feeder Mode ON means that all requests will get the response of OK first and then in background will run the query")
+	flag.BoolVar(&feederMode, "feeder-mode", false, "Feeder Mode ON means that all requests will get the response of OK first and then in background will run the query")
 	flag.BoolVar(&yamlconfig, "yamlconfig", false, "Use a yaml formated blacklist file")
 	flag.StringVar(&peersFileName, "peers-filename", "peersfile.txt", "Blacklists peers filename")
 

+ 19 - 1
peersarray.go

@@ -346,6 +346,15 @@ func (peersList *DrblPeers) Check(hostname string) (bool, int64) {
 	block := false
 
 	localWeight := peersList.HitWeight
+	if len(peersList.Peers) < 1 {
+		localWeight = 100 * 1024
+	}
+	if peersList.Debug {
+		fmt.Println("Peerlist size", peersList.Peers, "while checking:", hostname, "Local weigth:", localWeight)
+	}
+	if len(peersList.Peers) < 1 {
+		return block, localWeight
+	}
 
 	for _, peer := range peersList.Peers {
 		if localWeight <= int64(0) {
@@ -387,6 +396,15 @@ func (peersList *DrblPeers) CheckUrlWithSrc(requestUrl, src string) (bool, int64
 	block := false
 
 	localWeight := peersList.HitWeight
+	if len(peersList.Peers) < 1 {
+		localWeight = 100 * 1024
+	}
+	if peersList.Debug {
+		fmt.Println("Peerlist size", peersList.Peers, "while checking:", requestUrl, "For Source", src, "Local weigth:", localWeight)
+	}
+	if len(peersList.Peers) < 1 {
+		return block, localWeight
+	}
 
 	for _, peer := range peersList.Peers {
 
@@ -399,7 +417,7 @@ func (peersList *DrblPeers) CheckUrlWithSrc(requestUrl, src string) (bool, int64
 		if peer.Protocol == "http" || peer.Protocol == "https" {
 			// OK+		if peersList.Debug {
 			if peersList.Debug {
-				fmt.Println("peer", peer.Peername,"peer-protocol", peer.Protocol, ", results: found =>", found, "allow-access =>", allowaccess, "admin =>", admin, "url =>", requestUrl, "src =>", src)
+				fmt.Println("peer", peer.Peername, "peer-protocol", peer.Protocol, ", results: found =>", found, "allow-access =>", allowaccess, "admin =>", admin, "url =>", requestUrl, "src =>", src)
 			}
 		} else {
 			continue