-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgossip_dm.go
More file actions
35 lines (28 loc) · 916 Bytes
/
Copy pathgossip_dm.go
File metadata and controls
35 lines (28 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package nara
import (
"context"
"time"
"github.com/sirupsen/logrus"
"github.com/eljojo/nara/types"
)
// SendDM sends a SyncEvent directly to a target nara via HTTP POST to /dm.
// Returns true if the DM was successfully delivered.
// If delivery fails, the event should already be in the sender's ledger and
// will spread via gossip instead.
func (network *Network) SendDM(targetName types.NaraName, event SyncEvent) bool {
// Resolve nara name to ID
naraID := network.getNaraIDByName(targetName)
if naraID == "" {
logrus.Debugf("📬 Cannot DM %s: could not resolve nara ID", targetName)
return false
}
// Send via mesh client with timeout
ctx, cancel := context.WithTimeout(network.ctx, 15*time.Second)
defer cancel()
err := network.meshClient.SendDM(ctx, naraID, event)
if err != nil {
logrus.Debugf("📬 Failed to send DM to %s: %v", targetName, err)
return false
}
return true
}