scatter_net/scatter_net/peer/builder/methods/
finalize.rs

1use iroh::endpoint::Connection;
2
3use crate::{Peer, PeerBuilder, PeerInnerReadonly, PeerInnerWritable, PeerState, PeerUsage};
4
5impl PeerBuilder {
6    /// Finish the building process and connect to the Peer
7    #[must_use]
8    pub fn finalize(self, connection: Connection) -> Peer {
9        let Self {
10            direct_addresses: _,
11            net,
12            node_id,
13            relay_url: _,
14            peer_group,
15            state,
16        } = self;
17
18        let peer = Peer::from_inner(
19            PeerInnerReadonly { net, node_id },
20            PeerInnerWritable {
21                connection,
22                state: state.unwrap_or_else(|| PeerState {
23                    node_id,
24                    terminated: false,
25                    usage: PeerUsage::default(),
26                }),
27            },
28        );
29
30        if let Some(peer_group) = peer_group {
31            peer_group.insert_peer(peer.clone());
32        }
33
34        peer.init();
35
36        peer
37    }
38}