fix: align offer/answer tiebreak with yaw2/browser (lower ID offers)

The Go daemon was using higher-ID-offers while the browser adapter and
yaw2 use lower-ID-offers. This meant daemon↔browser pairs where the
daemon had the lower ID would never connect — neither side would offer.

All three comparison sites in anchor/client.go flipped: > 0 → < 0,
<= 0 → >= 0.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Fredrik Johansson
2026-06-25 11:47:13 +02:00
parent d529f58ddc
commit f7047b7bfe

View File

@@ -122,9 +122,8 @@ func runOnce(ctx context.Context, anchorURL, netHash string, id *crypto.Identity
if already {
continue
}
// Use the same lexicographic tiebreak as anchor join to avoid
// both sides trying to offer simultaneously.
if strings.Compare(string(id.PeerID()), string(pid)) <= 0 {
// Lower ID offers (matches yaw2/browser convention).
if strings.Compare(string(id.PeerID()), string(pid)) >= 0 {
continue
}
go func(pid proto.PeerID) {
@@ -170,7 +169,7 @@ func runOnce(ctx context.Context, anchorURL, netHash string, id *crypto.Identity
log.Printf("anchor: joined network, %d peer(s) present", len(msg.Peers))
for _, peerHex := range msg.Peers {
pid := proto.PeerID(peerHex)
if strings.Compare(string(id.PeerID()), peerHex) > 0 {
if strings.Compare(string(id.PeerID()), peerHex) < 0 {
go func(pid proto.PeerID) {
sess, err := startOffer(ctx, pid, id, m, s)
if err != nil {
@@ -187,7 +186,7 @@ func runOnce(ctx context.Context, anchorURL, netHash string, id *crypto.Identity
case proto.AnchorPeerJoin:
pid := proto.PeerID(msg.ID)
log.Printf("anchor: peer joined: %s", pid.Short())
if strings.Compare(string(id.PeerID()), msg.ID) > 0 {
if strings.Compare(string(id.PeerID()), msg.ID) < 0 {
go func(pid proto.PeerID) {
sess, err := startOffer(ctx, pid, id, m, s)
if err != nil {