/// Confirm and write a innernet invitation file after a peer has been created.
Confirm and write a innernet invitation file after a peer has been created.
Confirm and write a innernet invitation file after a peer has been created .
pub fn save_peer_invitation(
    network_name: &str,
    peer: &Peer,
    server_peer: &Peer,
    root_cidr: &Cidr,
    keypair: KeyPair,
    server_api_addr: &SocketAddr,
) -> Result<(), Error> {
    let peer_invitation = InterfaceConfig {
        interface: InterfaceInfo {
            network_name: network_name.to_string(),
            private_key: keypair.private.to_base64(),
            address: IpNetwork::new(peer.ip, root_cidr.prefix())?,
            listen_port: None,
        },
        server: ServerInfo {
            external_endpoint: server_peer
                .endpoint
                .expect("The innernet server should have a WireGuard endpoint"),
            internal_endpoint: *server_api_addr,
            public_key: server_peer.public_key.clone(),
        },
    };
    let invitation_save_path = Input::with_theme(&*THEME)
        .with_prompt("Save peer invitation file as")
        .default(format!("{}.toml", peer.name))
        .interact()?;
    peer_invitation.write_to_path(&invitation_save_path, true, None)?;
    println!(
        "\nPeer \"{}\" added\n\
         Peer invitation file written to {}\n\
         Please send it to them securely (eg. via magic-wormhole) \
         to bootstrap them onto the network.",
        peer.name.bold(),
        invitation_save_path.bold()
    );
    Ok(())
}
pub fn save_peer_invitation ( network_name : & str , peer : & Peer , server_peer : & Peer , root_cidr : & Cidr , keypair : KeyPair , server_api_addr : & SocketAddr , ) -> Result < ( ) , Error > { let peer_invitation = InterfaceConfig { interface : InterfaceInfo { network_name : network_name . to_string ( ) , private_key : keypair . private . to_base64 ( ) , address : IpNetwork :: new ( peer . ip , root_cidr . prefix ( ) ) ? , listen_port : None , } , server : ServerInfo { external_endpoint : server_peer . endpoint . expect ( " " ) , internal_endpoint : * server_api_addr , public_key : server_peer . public_key . clone ( ) , } , } ; let invitation_save_path = Input :: with_theme ( & * THEME ) . with_prompt ( " " ) . default ( format ! ( " " peer name ) ) . interact ( ) ? ; peer_invitation . write_to_path ( & invitation_save_path , true , None ) ? ; println ! ( " \n \" \" \n \
 \n \
 \
 " peer name bold ( ) invitation_save_path bold ( ) ) ; Ok ( ( ) ) }
Confirm and write a innernet invitation file after a peer has been created.
Confirm and write a innernet invitation file after a peer has been created .
network_name
&str
peer
&Peer
server_peer
&Peer
root_cidr
&Cidr
keypair
KeyPair
server_api_addr
&SocketAddr