Separate Initial Peer Requests and Retry Events
This commit is contained in:
parent
c73d0018dd
commit
6efde0289d
|
@ -57,7 +57,7 @@ func (cr *contactRetry) run() {
|
||||||
p.ticks++
|
p.ticks++
|
||||||
if p.ticks == p.backoff {
|
if p.ticks == p.backoff {
|
||||||
p.ticks = 0
|
p.ticks = 0
|
||||||
cr.bus.Publish(event.NewEvent(event.PeerRequest, map[event.Field]string{event.RemotePeer: p.id}))
|
cr.bus.Publish(event.NewEvent(event.RetryPeerRequest, map[event.Field]string{event.RemotePeer: p.id}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,17 @@ const (
|
||||||
StatusRequest = Type("StatusRequest")
|
StatusRequest = Type("StatusRequest")
|
||||||
ProtocolEngineStatus = Type("ProtocolEngineStatus")
|
ProtocolEngineStatus = Type("ProtocolEngineStatus")
|
||||||
|
|
||||||
|
// Attempt to outbound peer with a given remote peer
|
||||||
|
// attributes:
|
||||||
|
// RemotePeer: [eg "chpr7qm6op5vfcg2pi4vllco3h6aa7exexc4rqwnlupqhoogx2zgd6qd"
|
||||||
PeerRequest = Type("PeerRequest")
|
PeerRequest = Type("PeerRequest")
|
||||||
|
|
||||||
|
// RetryPeerRequest
|
||||||
|
// Identical to PeerRequest, but allows Engine to make decisions regarding blocked peers
|
||||||
|
// attributes:
|
||||||
|
// RemotePeer: [eg "chpr7qm6op5vfcg2pi4vllco3h6aa7exexc4rqwnlupqhoogx2zgd6qd"
|
||||||
|
RetryPeerRequest = Type("RetryPeerRequest")
|
||||||
|
|
||||||
// Blocking Events both Block and Unblock have the same structure
|
// Blocking Events both Block and Unblock have the same structure
|
||||||
// attributes:
|
// attributes:
|
||||||
// RemotePeer: [eg "chpr7qm6op5vfcg2pi4vllco3h6aa7exexc4rqwnlupqhoogx2zgd6qd"
|
// RemotePeer: [eg "chpr7qm6op5vfcg2pi4vllco3h6aa7exexc4rqwnlupqhoogx2zgd6qd"
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
|
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
|
||||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||||
|
"git.openprivacy.ca/openprivacy/libricochet-go/utils"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"golang.org/x/crypto/ed25519"
|
"golang.org/x/crypto/ed25519"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -73,6 +74,7 @@ func NewProtocolEngine(identity primitives.Identity, privateKey ed25519.PrivateK
|
||||||
|
|
||||||
engine.eventManager.Subscribe(event.ProtocolEngineStartListen, engine.queue)
|
engine.eventManager.Subscribe(event.ProtocolEngineStartListen, engine.queue)
|
||||||
engine.eventManager.Subscribe(event.PeerRequest, engine.queue)
|
engine.eventManager.Subscribe(event.PeerRequest, engine.queue)
|
||||||
|
engine.eventManager.Subscribe(event.RetryPeerRequest, engine.queue)
|
||||||
engine.eventManager.Subscribe(event.InvitePeerToGroup, engine.queue)
|
engine.eventManager.Subscribe(event.InvitePeerToGroup, engine.queue)
|
||||||
engine.eventManager.Subscribe(event.JoinServer, engine.queue)
|
engine.eventManager.Subscribe(event.JoinServer, engine.queue)
|
||||||
engine.eventManager.Subscribe(event.SendMessageToGroup, engine.queue)
|
engine.eventManager.Subscribe(event.SendMessageToGroup, engine.queue)
|
||||||
|
@ -111,8 +113,16 @@ func (e *engine) eventHandler() {
|
||||||
case event.StatusRequest:
|
case event.StatusRequest:
|
||||||
e.eventManager.Publish(event.Event{EventType: event.ProtocolEngineStatus, EventID: ev.EventID})
|
e.eventManager.Publish(event.Event{EventType: event.ProtocolEngineStatus, EventID: ev.EventID})
|
||||||
case event.PeerRequest:
|
case event.PeerRequest:
|
||||||
e.blocked.Store(ev.Data[event.RemotePeer], false)
|
if utils.IsValidHostname(ev.Data[event.RemotePeer]) {
|
||||||
go e.peerWithOnion(ev.Data[event.RemotePeer])
|
e.blocked.Store(ev.Data[event.RemotePeer], false)
|
||||||
|
go e.peerWithOnion(ev.Data[event.RemotePeer])
|
||||||
|
}
|
||||||
|
case event.RetryPeerRequest:
|
||||||
|
// This event allows engine to treat (automated) retry peering requests differently to user-specified
|
||||||
|
// peer events
|
||||||
|
if utils.IsValidHostname(ev.Data[event.RemotePeer]) {
|
||||||
|
go e.peerWithOnion(ev.Data[event.RemotePeer])
|
||||||
|
}
|
||||||
case event.InvitePeerToGroup:
|
case event.InvitePeerToGroup:
|
||||||
e.sendMessageToPeer(ev.EventID, ev.Data[event.RemotePeer], event.ContextInvite, []byte(ev.Data[event.GroupInvite]))
|
e.sendMessageToPeer(ev.EventID, ev.Data[event.RemotePeer], event.ContextInvite, []byte(ev.Data[event.GroupInvite]))
|
||||||
case event.JoinServer:
|
case event.JoinServer:
|
||||||
|
|
Loading…
Reference in New Issue