diff --git a/plugins/autopeering/protocol/outgoing_request_processor.go b/plugins/autopeering/protocol/outgoing_request_processor.go index 88b95669ef2931d1b5d3080b42da70d7bf872242..ea2f37459d7f3876105d30a8b2b3461bac99ca22 100644 --- a/plugins/autopeering/protocol/outgoing_request_processor.go +++ b/plugins/autopeering/protocol/outgoing_request_processor.go @@ -1,6 +1,9 @@ package protocol import ( + "github.com/iotaledger/goshimmer/plugins/autopeering/instances/outgoingrequest" + "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/types" + "github.com/iotaledger/goshimmer/plugins/autopeering/server/tcp" "time" "github.com/iotaledger/goshimmer/packages/timeutil" @@ -10,10 +13,7 @@ import ( "github.com/iotaledger/goshimmer/packages/node" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/acceptedneighbors" "github.com/iotaledger/goshimmer/plugins/autopeering/instances/chosenneighbors" - "github.com/iotaledger/goshimmer/plugins/autopeering/instances/outgoingrequest" "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/constants" - "github.com/iotaledger/goshimmer/plugins/autopeering/protocol/types" - "github.com/iotaledger/goshimmer/plugins/autopeering/server/tcp" "github.com/iotaledger/goshimmer/plugins/autopeering/types/peer" ) @@ -46,14 +46,27 @@ func sendOutgoingRequests(plugin *node.Plugin) { timeutil.Sleep(5 * time.Second) if candidateShouldBeContacted(chosenNeighborCandidate) { - if dialed, err := chosenNeighborCandidate.Send(outgoingrequest.INSTANCE.Marshal(), types.PROTOCOL_TYPE_TCP, true); err != nil { - plugin.LogDebug(err.Error()) - } else { - plugin.LogDebug("sent peering request to " + chosenNeighborCandidate.String()) + doneChan := make(chan int, 1) + + go func(doneChan chan int) { + if dialed, err := chosenNeighborCandidate.Send(outgoingrequest.INSTANCE.Marshal(), types.PROTOCOL_TYPE_TCP, true); err != nil { + plugin.LogDebug(err.Error()) + } else { + plugin.LogDebug("sent peering request to " + chosenNeighborCandidate.String()) - if dialed { - tcp.HandleConnection(chosenNeighborCandidate.Conn) + if dialed { + tcp.HandleConnection(chosenNeighborCandidate.Conn) + } } + + close(doneChan) + }(doneChan) + + select { + case <-daemon.ShutdownSignal: + return + case <-doneChan: + continue } } }