Simplify Network Check Plugin - Drop Self-Checks from Connectivity Plugin #436
|
@ -131,6 +131,12 @@ func (cr *contactRetry) retryDisconnected() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cr *contactRetry) handleEvent(id string, state connections.ConnectionState, ctype connectionType) {
|
func (cr *contactRetry) handleEvent(id string, state connections.ConnectionState, ctype connectionType) {
|
||||||
|
|
||||||
|
// don't handle contact retries for ourselves
|
||||||
|
if id == cr.onion {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if _, exists := cr.connections.Load(id); !exists {
|
if _, exists := cr.connections.Load(id); !exists {
|
||||||
p := &contact{id: id, state: state, backoff: 0, ticks: 0, ctype: ctype}
|
p := &contact{id: id, state: state, backoff: 0, ticks: 0, ctype: ctype}
|
||||||
cr.connections.Store(id, p)
|
cr.connections.Store(id, p)
|
||||||
|
|
|
@ -18,19 +18,19 @@ const NetworkCheckSuccess = "Success"
|
||||||
|
|
||||||
// networkCheck is a convenience plugin for testing high level availability of onion services
|
// networkCheck is a convenience plugin for testing high level availability of onion services
|
||||||
type networkCheck struct {
|
type networkCheck struct {
|
||||||
bus event.Manager
|
bus event.Manager
|
||||||
queue event.Queue
|
queue event.Queue
|
||||||
acn connectivity.ACN
|
onion string
|
||||||
onionsToCheck sync.Map // onion:string => true:bool
|
acn connectivity.ACN
|
||||||
breakChan chan bool
|
breakChan chan bool
|
||||||
running bool
|
running bool
|
||||||
offline bool
|
offline bool
|
||||||
offlineLock sync.Mutex
|
offlineLock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewNetworkCheck returns a Plugin that when started will attempt various network tests
|
// NewNetworkCheck returns a Plugin that when started will attempt various network tests
|
||||||
func NewNetworkCheck(bus event.Manager, acn connectivity.ACN) Plugin {
|
func NewNetworkCheck(onion string, bus event.Manager, acn connectivity.ACN) Plugin {
|
||||||
nc := &networkCheck{bus: bus, acn: acn, queue: event.NewQueue(), breakChan: make(chan bool, 1)}
|
nc := &networkCheck{onion: onion, bus: bus, acn: acn, queue: event.NewQueue(), breakChan: make(chan bool, 1)}
|
||||||
return nc
|
return nc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,12 +61,13 @@ func (nc *networkCheck) run() {
|
||||||
// and then we will wait a minute and check the connection for the first time (the onion should be up)
|
// and then we will wait a minute and check the connection for the first time (the onion should be up)
|
||||||
// under normal operating circumstances
|
// under normal operating circumstances
|
||||||
case event.ProtocolEngineStartListen:
|
case event.ProtocolEngineStartListen:
|
||||||
if _, exists := nc.onionsToCheck.Load(e.Data[event.Onion]); !exists {
|
if nc.onion == (e.Data[event.Onion]) {
|
||||||
log.Debugf("initiating connection check for %v", e.Data[event.Onion])
|
log.Debugf("initiating connection check for %v", e.Data[event.Onion])
|
||||||
nc.onionsToCheck.Store(e.Data[event.Onion], true)
|
|
||||||
if time.Since(lastMessageReceived) > time.Minute {
|
if time.Since(lastMessageReceived) > time.Minute {
|
||||||
nc.selfTest()
|
nc.selfTest()
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.Errorf("network check plugin received an event for a different profile than it was started with. Internal wiring is probably wrong.")
|
||||||
}
|
}
|
||||||
case event.PeerStateChange:
|
case event.PeerStateChange:
|
||||||
fallthrough
|
fallthrough
|
||||||
|
@ -114,10 +115,7 @@ func (nc *networkCheck) Shutdown() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nc *networkCheck) selfTest() {
|
func (nc *networkCheck) selfTest() {
|
||||||
nc.onionsToCheck.Range(func(key, val interface{}) bool {
|
go nc.checkConnection(nc.onion)
|
||||||
go nc.checkConnection(key.(string))
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -27,7 +27,7 @@ func Get(id PluginID, bus event.Manager, acn connectivity.ACN, onion string) (Pl
|
||||||
case CONNECTIONRETRY:
|
case CONNECTIONRETRY:
|
||||||
return NewConnectionRetry(bus, onion), nil
|
return NewConnectionRetry(bus, onion), nil
|
||||||
case NETWORKCHECK:
|
case NETWORKCHECK:
|
||||||
return NewNetworkCheck(bus, acn), nil
|
return NewNetworkCheck(onion, bus, acn), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("plugin not defined %v", id)
|
return nil, fmt.Errorf("plugin not defined %v", id)
|
||||||
|
|
|
@ -240,7 +240,7 @@ func checkCwtchProfileBackupFile(srcFile string) (string, error) {
|
||||||
profileFileType := parts[1]
|
profileFileType := parts[1]
|
||||||
|
|
||||||
_, hexErr := hex.DecodeString(dir)
|
_, hexErr := hex.DecodeString(dir)
|
||||||
if dir == "." || dir == ".." || len(dir) !=32 || hexErr != nil {
|
if dir == "." || dir == ".." || len(dir) != 32 || hexErr != nil {
|
||||||
return "", errors.New("invalid profile name")
|
return "", errors.New("invalid profile name")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue