simple_node.rs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. use std::net::SocketAddr;
  2. use fleck::fleck_core;
  3. fn main() {
  4. pretty_env_logger::init_timed();
  5. let fleck = fleck::API::new();
  6. // generate ephemeral keypair
  7. fleck.with_service(|ns: &fleck_core::NodeService| {
  8. ns.build_ephemeral_self_node();
  9. });
  10. // create UDP socket for communication with a local multicast group
  11. let sockref = fleck.with_service(|io: &fleck_core::io::IOService| {
  12. fleck_core::io::UdpSocketBuilder::default()
  13. .bind_to(SocketAddr::new(
  14. std::net::Ipv4Addr::UNSPECIFIED.into(),
  15. 3535,
  16. ))
  17. .join_multicast("239.0.239.0".parse().unwrap(), "0.0.0.0".parse().unwrap())
  18. .build(io)
  19. });
  20. // enable local discovery
  21. fleck.with_service(|ld: &fleck_core::discovery::LocalDiscovery| {
  22. for peer in sockref.multicast_peers() {
  23. ld.add_multicast_peer(peer);
  24. }
  25. });
  26. // run and perform all automatic services, but don't do anything interesting...
  27. fleck.run();
  28. }