Skip to content

Conversation

@sedited
Copy link
Member

@sedited sedited commented Nov 18, 2022

Based on @Lederstrumpf farcasterd.dev-testing branch.

sedited and others added 26 commits November 14, 2022 17:15
Peer messages sent to a remote peer are now cached until the remote peer
has replied with a corresponding receipt.

If the connection fails in a listener spawned peerd, the cache is
emptied before peerd shuts down and the messages are sent back to their
respective origin (swapd). Swapd then processes them into its own cache.

If the connection fails in a connecting peerd, the cache is only emptied
once the reconnect has been a success. Messages are not sent back to
their origin.
This allows us to consistently inform the user on the connection status
of the swap.

Peerd now emits Disconnected and Reconnected requests to farcasterd,
which in turn can route them on to swapd.
The connect command now allows a user to manually trigger a connect for
a restored swap that was previously unable to connect.
was calling colorize func, not swap_id itself
// is only possible to a listening peer, its address thus has to
// match the address of the offer.
if peerd.is_none() {
Some(ServiceId::Peer(node_addr_from_public_offer(public_offer)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with a taker that successively takes offers from the maker once the last completes: if the last successful run was Bob maker, then Alice taker will most likely terminate connection before Bob has sweeped his xmr. Then Alice launches another swap.

In my understanding, a new peer connection will not be registered because awaiting_connect_from(..) will still match against the tsm of the last successful run here, since Bob's peerd is down, yet node_addr_from_public_offer(..) is the same for the old and the new swap?

Copy link
Member Author

@sedited sedited Nov 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't quite understand how this triggers a state where the peerd.is_none(), but this has to be the case, so I added an additional check to only trigger this when taking / connecting a swap.

@sedited sedited force-pushed the peerdConnectTreatmeant branch from b022b00 to cc47368 Compare November 20, 2022 12:13
);
}
}
let peerd_up = runtime.registered_services.contains(&peerd);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with a unique ServiceId for every peerd instantiation, if we create a new peerd instance for a remote and kill the old one, this will return false since the old peerd's ServiceId is cached in the tsm but won't be in the runtime.registered_services anymore, so swap will never launch. So we can instead here check only against the node address of the peerd key in runtime.registered_services, but if there are multiple concurrent peerds living for said remote, then still should ensure that we launch with the latest one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed a commit that does an ugly impl of this. TODO if we go with this change:

  1. it currently just uses the first peerd it finds in registered services - imo we'd need to encode creation time in the peerd ServiceId to do that correctly
  2. the SwapdLaunched struct should not keep the full peerd ServiceId since only the NodeAddr is read with this change

@Lederstrumpf Lederstrumpf added the farcaster.dev testing Currently apply (or to be applied) on farcaster.dev backend label Nov 24, 2022
@sedited sedited force-pushed the peerdConnectTreatmeant branch from 56fb536 to b8484ac Compare November 28, 2022 17:36
sedited and others added 21 commits November 28, 2022 18:38
Handle Connect msg properly for running and restoring swapd

Peerd: Add a Pong to our own hacky handshake

Peerd: Only insert protocol messages to unchecked_msg_cache
Farcaster: Correct handling of restoring tsm connection
Ensure ConnectSuccess message is only expected for Taker swaps

Handle new and failed connections in a coherent manner

Trigger peerd termination externally, not internally
log swapids if awaiting connection
Peerd: Emit Reconnected only after checking cached messages

Do not reconnect as a listener-spawned peerd
The peerd service Id is now randomized per instance
@sedited sedited force-pushed the peerdConnectTreatmeant branch from b8484ac to 7745f55 Compare November 28, 2022 17:40
@sedited
Copy link
Member Author

sedited commented Nov 28, 2022

Closing this PR in favor of #792

@sedited sedited closed this Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

farcaster.dev testing Currently apply (or to be applied) on farcaster.dev backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants