Skip to main content

connexa/
lib.rs

1pub mod behaviour;
2pub mod builder;
3pub mod error;
4pub mod handle;
5pub mod keystore;
6mod multiaddr_ext;
7pub mod task;
8pub(crate) mod types;
9
10use crate::behaviour::BehaviourEvent;
11use crate::keystore::Keychain;
12use libp2p::identity::Keypair;
13use libp2p::swarm::NetworkBehaviour;
14use libp2p::swarm::{Swarm, SwarmEvent};
15use std::task::{Context, Poll};
16
17pub(crate) type TTaskCallback<B, Ctx, Cmd, Store, K> = Box<
18    dyn Fn(&mut Swarm<behaviour::Behaviour<B, Store>>, &Keychain<K>, &mut Ctx, Cmd)
19        + 'static
20        + Send,
21>;
22pub(crate) type TEventCallback<B, Ctx, Store, K> = Box<
23    dyn Fn(
24            &mut Swarm<behaviour::Behaviour<B, Store>>,
25            &Keychain<K>,
26            &mut Ctx,
27            <B as NetworkBehaviour>::ToSwarm,
28        )
29        + 'static
30        + Send,
31>;
32pub(crate) type TPollableCallback<B, Ctx, Store, K> = Box<
33    dyn Fn(
34            &mut Context,
35            &mut Swarm<behaviour::Behaviour<B, Store>>,
36            &Keychain<K>,
37            &mut Ctx,
38        ) -> Poll<()>
39        + 'static
40        + Send,
41>;
42pub(crate) type TSwarmEventCallback<B, Ctx, Store, K> = Box<
43    dyn Fn(
44            &mut Swarm<behaviour::Behaviour<B, Store>>,
45            &Keychain<K>,
46            &SwarmEvent<BehaviourEvent<B, Store>>,
47            &mut Ctx,
48        )
49        + 'static
50        + Send,
51>;
52
53pub(crate) type TPreloadCallback<B, Ctx, Store, K> = Box<
54    dyn FnOnce(&Keypair, &mut Swarm<behaviour::Behaviour<B, Store>>, &Keychain<K>, &mut Ctx)
55        + 'static
56        + Send,
57>;
58
59pub mod dummy {
60    pub use crate::behaviour::dummy::{Behaviour, DummyHandler};
61}
62
63pub mod prelude {
64    use crate::builder::ConnexaBuilder;
65    pub use crate::multiaddr_ext::MultiaddrExt;
66    pub use crate::types::*;
67    pub use libp2p::{Multiaddr, PeerId, Stream, StreamProtocol, multiaddr::Protocol};
68
69    pub use crate::handle::swarm::ConnectionTarget;
70
71    use crate::prelude::peer_store::store::memory::MemoryStore;
72    pub use libp2p::identity;
73
74    pub mod swarm {
75        pub use libp2p::SwarmBuilder;
76        pub use libp2p::swarm::*;
77    }
78
79    pub mod peer_store {
80        pub use crate::behaviour::peer_store::store;
81    }
82
83    #[cfg(feature = "kad")]
84    pub mod dht {
85        pub use crate::handle::dht::{ToOptionalRecordKey, ToRecordKey};
86        pub use libp2p::kad::*;
87    }
88
89    #[cfg(feature = "request-response")]
90    pub mod request_response {
91        pub use crate::handle::request_response::{IntoRequest, OptionalStreamProtocol};
92        pub use libp2p::request_response::{
93            Config, Event, InboundFailure, InboundRequestId, Message, OutboundFailure,
94            OutboundRequestId, ProtocolSupport,
95        };
96    }
97
98    #[cfg(feature = "stream")]
99    pub mod stream {
100        pub use crate::handle::stream::IntoStreamProtocol;
101        pub use libp2p_stream::{Control, IncomingStreams, OpenStreamError};
102    }
103
104    #[cfg(feature = "relay")]
105    pub mod relay {
106        pub mod server {
107            // TODO: Determine if CircuitId is needed
108            pub use libp2p::relay::{Config, Event, RateLimiter, StatusCode};
109        }
110
111        pub mod client {
112            pub use libp2p::relay::client::Event;
113        }
114    }
115
116    #[cfg(feature = "dcutr")]
117    pub mod dcutr {
118        pub use libp2p::dcutr::{Error, Event};
119    }
120
121    #[cfg(feature = "ping")]
122    pub mod ping {
123        pub use libp2p::ping::{Config, Event, Failure};
124    }
125
126    #[cfg(feature = "identify")]
127    pub mod identify {
128        pub use libp2p::identify::{Config, Event, Info, UpgradeError};
129    }
130
131    #[cfg(feature = "gossipsub")]
132    pub mod gossipsub {
133        pub use crate::handle::gossipsub::IntoTopic as IntoGossipsubTopic;
134        pub use libp2p::gossipsub::{
135            AllowAllSubscriptionFilter, Config, ConfigBuilder, Event, IdentTopic, Message,
136            MessageAcceptance, MessageAuthenticity, MessageId, Sha256Topic, Topic, TopicHash,
137            ValidationMode, Version,
138        };
139    }
140
141    #[cfg(feature = "floodsub")]
142    pub mod floodsub {
143        pub use crate::handle::floodsub::IntoTopic as IntoFloodsubTopic;
144        pub use libp2p::floodsub::{Config, Event, Topic};
145    }
146
147    #[cfg(feature = "rendezvous")]
148    pub mod rendezvous {
149        pub use crate::handle::rendezvous::IntoNamespace;
150        pub use libp2p::rendezvous::{
151            Cookie, ErrorCode, MAX_NAMESPACE, MAX_TTL, MIN_TTL, Namespace, Registration,
152        };
153    }
154
155    #[cfg(feature = "mdns")]
156    #[cfg(not(target_arch = "wasm32"))]
157    pub mod mdns {
158        pub use libp2p::mdns::{Config, Event};
159    }
160
161    #[cfg(feature = "autonat")]
162    pub mod autonat {
163        pub mod v1 {
164            pub use libp2p::autonat::v1::{
165                Config, Event, InboundFailure, InboundProbeError, InboundProbeEvent,
166            };
167        }
168
169        pub mod v2 {
170            pub mod server {
171                pub use libp2p::autonat::v2::server::Event;
172            }
173
174            pub mod client {
175                pub use libp2p::autonat::v2::client::{Config, Event};
176            }
177        }
178    }
179
180    #[cfg(feature = "upnp")]
181    #[cfg(not(target_arch = "wasm32"))]
182    pub mod upnp {
183        pub use libp2p::upnp::Event;
184    }
185
186    pub mod connection_limits {
187        pub use libp2p_connection_limits::{ConnectionLimits, Exceeded};
188    }
189
190    pub mod transport {
191        #[cfg(feature = "dns")]
192        pub mod dns {
193            pub use crate::builder::transport::DnsResolver;
194        }
195        pub use libp2p::core::muxing;
196        pub use libp2p::core::transport;
197        pub use libp2p::core::upgrade;
198        pub use libp2p::core::{ConnectedPoint, Endpoint};
199        #[cfg(feature = "noise")]
200        pub use libp2p::noise;
201        #[cfg(feature = "pnet")]
202        pub use libp2p::pnet;
203        #[cfg(feature = "quic")]
204        #[cfg(not(target_arch = "wasm32"))]
205        pub use libp2p::quic;
206        #[cfg(feature = "tcp")]
207        #[cfg(not(target_arch = "wasm32"))]
208        pub use libp2p::tcp;
209        #[cfg(feature = "websocket")]
210        #[cfg(not(target_arch = "wasm32"))]
211        pub use libp2p::websocket;
212        #[cfg(feature = "yamux")]
213        pub use libp2p::yamux;
214    }
215
216    pub type DefaultConnexaBuilder = ConnexaBuilder<
217        super::dummy::Behaviour,
218        (),
219        (),
220        MemoryStore,
221        crate::keystore::store::memory::MemoryKeystore,
222    >;
223}