12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- use fleck::fleck_core;
- use clap::Parser;
- #[derive(Parser, Debug)]
- struct SocketArgs {
- #[arg(short, long)]
- server: bool,
- filename: String,
- }
- fn main() {
- pretty_env_logger::init_timed();
- let args = SocketArgs::parse();
- let fleck = fleck::API::new();
- // generate ephemeral keypair
- fleck.with_service(|ns: &fleck_core::NodeService| {
- ns.build_ephemeral_self_node();
- });
- let sockref = fleck.with_service(|io: &fleck_core::io::IOService| {
- let builder = fleck_core::io::UnixSocketBuilder::default().set_path(args.filename);
- if args.server {
- builder.serve_mode().build(io)
- } else {
- builder.connect_mode().build(io)
- }
- });
- if !args.server {
- fleck.with_service(|ds: &fleck_core::discovery::PeerDiscovery| {
- ds.new_peer(sockref.connected_peer());
- });
- }
- // enable local discovery
- /*fleck.with_service(|ld: &fleck_core::discovery::LocalDiscovery| {
- for peer in sockref.multicast_peers() {
- ld.add_multicast_peer(peer);
- }
- });*/
- // run and perform all automatic services, but don't do anything interesting...
- fleck.run();
- }
|