From 78d174c6e44d3fa808d9fb3be70f240841858b2b Mon Sep 17 00:00:00 2001
From: Hans Moog <hm@mkjc.net>
Date: Mon, 22 Jul 2019 19:43:12 +0200
Subject: [PATCH] Feat: added flags to disable autopeering for entry nodes

---
 plugins/autopeering/parameters/parameters.go         |  8 +++++---
 .../protocol/incoming_request_processor.go           |  4 +++-
 plugins/autopeering/protocol/plugin.go               | 12 +++++++++++-
 3 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/plugins/autopeering/parameters/parameters.go b/plugins/autopeering/parameters/parameters.go
index 7f365c60..72992708 100644
--- a/plugins/autopeering/parameters/parameters.go
+++ b/plugins/autopeering/parameters/parameters.go
@@ -3,7 +3,9 @@ package parameters
 import "github.com/iotaledger/goshimmer/packages/parameter"
 
 var (
-	ADDRESS     = parameter.AddString("AUTOPEERING/ADDRESS", "0.0.0.0", "address to bind for incoming peering requests")
-	ENTRY_NODES = parameter.AddString("AUTOPEERING/ENTRY_NODES", "0d828930890386f036eb77982cc067c5429f7b8f@82.165.29.179:14626", "list of trusted entry nodes for auto peering")
-	PORT        = parameter.AddInt("AUTOPEERING/PORT", 14626, "tcp port for incoming peering requests")
+	ADDRESS         = parameter.AddString("AUTOPEERING/ADDRESS", "0.0.0.0", "address to bind for incoming peering requests")
+	ENTRY_NODES     = parameter.AddString("AUTOPEERING/ENTRY_NODES", "0d828930890386f036eb77982cc067c5429f7b8f@82.165.29.179:14626", "list of trusted entry nodes for auto peering")
+	PORT            = parameter.AddInt("AUTOPEERING/PORT", 14626, "tcp port for incoming peering requests")
+	ACCEPT_REQUESTS = parameter.AddBool("AUTOPEERING/ACCEPT_REQUESTS", true, "accept incoming autopeering requests")
+	SEND_REQUESTS   = parameter.AddBool("AUTOPEERING/SEND_REQUESTS", true, "send autopeering requests")
 )
diff --git a/plugins/autopeering/protocol/incoming_request_processor.go b/plugins/autopeering/protocol/incoming_request_processor.go
index 460caedb..75d580af 100644
--- a/plugins/autopeering/protocol/incoming_request_processor.go
+++ b/plugins/autopeering/protocol/incoming_request_processor.go
@@ -3,6 +3,8 @@ package protocol
 import (
 	"math/rand"
 
+	"github.com/iotaledger/goshimmer/plugins/autopeering/parameters"
+
 	"github.com/iotaledger/goshimmer/packages/events"
 	"github.com/iotaledger/goshimmer/packages/node"
 	"github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors"
@@ -25,7 +27,7 @@ func processIncomingRequest(plugin *node.Plugin, req *request.Request) {
 
 	knownpeers.INSTANCE.AddOrUpdate(req.Issuer)
 
-	if requestShouldBeAccepted(req) {
+	if *parameters.ACCEPT_REQUESTS.Value && requestShouldBeAccepted(req) {
 		defer acceptedneighbors.INSTANCE.Lock()()
 
 		if requestShouldBeAccepted(req) {
diff --git a/plugins/autopeering/protocol/plugin.go b/plugins/autopeering/protocol/plugin.go
index a1b175fc..d8cc9eba 100644
--- a/plugins/autopeering/protocol/plugin.go
+++ b/plugins/autopeering/protocol/plugin.go
@@ -1,8 +1,11 @@
 package protocol
 
 import (
+	"fmt"
+
 	"github.com/iotaledger/goshimmer/packages/daemon"
 	"github.com/iotaledger/goshimmer/packages/node"
+	"github.com/iotaledger/goshimmer/plugins/autopeering/parameters"
 	"github.com/iotaledger/goshimmer/plugins/autopeering/server/tcp"
 	"github.com/iotaledger/goshimmer/plugins/autopeering/server/udp"
 )
@@ -22,6 +25,13 @@ func Configure(plugin *node.Plugin) {
 func Run(plugin *node.Plugin) {
 	daemon.BackgroundWorker("Autopeering Chosen Neighbor Dropper", createChosenNeighborDropper(plugin))
 	daemon.BackgroundWorker("Autopeering Accepted Neighbor Dropper", createAcceptedNeighborDropper(plugin))
-	daemon.BackgroundWorker("Autopeering Outgoing Request Processor", createOutgoingRequestProcessor(plugin))
+
+	fmt.Println(*parameters.SEND_REQUESTS.Value)
+	fmt.Println(*parameters.ACCEPT_REQUESTS.Value)
+
+	if *parameters.SEND_REQUESTS.Value {
+		daemon.BackgroundWorker("Autopeering Outgoing Request Processor", createOutgoingRequestProcessor(plugin))
+	}
+
 	daemon.BackgroundWorker("Autopeering Outgoing Ping Processor", createOutgoingPingProcessor(plugin))
 }
-- 
GitLab