unix_socket.rs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. use fleck::fleck_core;
  2. use clap::Parser;
  3. #[derive(Parser, Debug)]
  4. struct SocketArgs {
  5. #[arg(short, long)]
  6. server: bool,
  7. filename: String,
  8. }
  9. fn main() {
  10. pretty_env_logger::init_timed();
  11. let args = SocketArgs::parse();
  12. let fleck = fleck::API::new();
  13. // generate ephemeral keypair
  14. fleck.with_service(|ns: &fleck_core::NodeService| {
  15. ns.build_ephemeral_self_node();
  16. });
  17. let sockref = fleck.with_service(|io: &fleck_core::io::IOService| {
  18. let builder = fleck_core::io::UnixSocketBuilder::default().set_path(args.filename);
  19. if args.server {
  20. builder.serve_mode().build(io)
  21. } else {
  22. builder.connect_mode().build(io)
  23. }
  24. });
  25. if !args.server {
  26. fleck.with_service(|ds: &fleck_core::discovery::PeerDiscovery| {
  27. ds.new_peer(sockref.connected_peer());
  28. });
  29. }
  30. // enable local discovery
  31. /*fleck.with_service(|ld: &fleck_core::discovery::LocalDiscovery| {
  32. for peer in sockref.multicast_peers() {
  33. ld.add_multicast_peer(peer);
  34. }
  35. });*/
  36. // run and perform all automatic services, but don't do anything interesting...
  37. fleck.run();
  38. }