also notify when the peer is online

This commit is contained in:
Jesse de Wit
2023-11-20 12:10:43 +01:00
parent 3f5d10e629
commit 42123bd40b

View File

@@ -139,9 +139,15 @@ func (i *Interceptor) Intercept(req common.InterceptRequest) common.InterceptRes
}
}
if !isConnected {
if isConnected {
// If the peer is connected, notify anyway, but don't wait for the result.
go i.notificationService.Notify(
hex.EncodeToString(nextHop),
reqPaymentHashStr,
)
} else {
// Make sure the client is connected by potentially notifying them to come online.
notifyResult := i.notify(reqPaymentHashStr, nextHop, isRegistered)
notifyResult := i.notifyAndWait(reqPaymentHashStr, nextHop, isRegistered)
if notifyResult != nil {
log.Printf("paymentHash: %s, !isConnected and notifyResult != nil", reqPaymentHashStr)
return *notifyResult, nil
@@ -273,7 +279,7 @@ func (i *Interceptor) Intercept(req common.InterceptRequest) common.InterceptRes
return resp.(common.InterceptResult)
}
func (i *Interceptor) notify(reqPaymentHashStr string, nextHop []byte, isRegistered bool) *common.InterceptResult {
func (i *Interceptor) notifyAndWait(reqPaymentHashStr string, nextHop []byte, isRegistered bool) *common.InterceptResult {
// If not connected, send a notification to the registered
// notification service for this client if available.
notified, err := i.notificationService.Notify(