11//! Pluto behaviour.
22
3+ use std:: sync:: LazyLock ;
4+
35use libp2p:: { identify, identity:: Keypair , ping, relay, swarm:: NetworkBehaviour } ;
46
57use crate :: { config:: default_ping_config, gater:: ConnGater } ;
@@ -29,18 +31,28 @@ impl PlutoBehaviour {
2931 }
3032}
3133
34+ /// The default user agent for the Pluto network.
35+ pub static DEFAULT_USER_AGENT : LazyLock < String > =
36+ LazyLock :: new ( || format ! ( "pluto/{}" , * charon_core:: version:: VERSION ) ) ;
37+
38+ /// The default identify protocol for the Pluto network.
39+ pub static DEFAULT_IDENTIFY_PROTOCOL : LazyLock < String > =
40+ LazyLock :: new ( || format ! ( "/pluto/{}" , * charon_core:: version:: VERSION ) ) ;
41+
3242/// Builder for [`PlutoBehaviour`].
3343#[ derive( Debug , Clone ) ]
3444pub struct PlutoBehaviourBuilder {
3545 gater : Option < ConnGater > ,
3646 identify_protocol : String ,
47+ user_agent : String ,
3748}
3849
3950impl Default for PlutoBehaviourBuilder {
4051 fn default ( ) -> Self {
4152 Self {
4253 gater : None ,
43- identify_protocol : "/pluto/1.0.0-alpha" . into ( ) ,
54+ identify_protocol : DEFAULT_IDENTIFY_PROTOCOL . clone ( ) ,
55+ user_agent : DEFAULT_USER_AGENT . clone ( ) ,
4456 }
4557 }
4658}
@@ -63,6 +75,12 @@ impl PlutoBehaviourBuilder {
6375 self
6476 }
6577
78+ /// Sets the user agent string.
79+ pub fn with_user_agent ( mut self , user_agent : impl Into < String > ) -> Self {
80+ self . user_agent = user_agent. into ( ) ;
81+ self
82+ }
83+
6684 /// Builds the [`PlutoBehaviour`] with the provided keypair and relay
6785 /// client.
6886 pub fn build ( self , key : & Keypair , relay_client : relay:: client:: Behaviour ) -> PlutoBehaviour {
@@ -71,10 +89,10 @@ impl PlutoBehaviourBuilder {
7189 . gater
7290 . unwrap_or_else ( || ConnGater :: new_conn_gater ( vec ! [ ] , vec ! [ ] ) ) ,
7391 relay : relay_client,
74- identify : identify:: Behaviour :: new ( identify :: Config :: new (
75- self . identify_protocol ,
76- key . public ( ) ,
77- ) ) ,
92+ identify : identify:: Behaviour :: new (
93+ identify :: Config :: new ( self . identify_protocol , key . public ( ) )
94+ . with_agent_version ( self . user_agent ) ,
95+ ) ,
7896 ping : ping:: Behaviour :: new ( default_ping_config ( ) ) ,
7997 }
8098 }
0 commit comments