@@ -24,29 +24,26 @@ impl DriaBehaviour {
24
24
let peer_id = public_key. to_peer_id ( ) ;
25
25
Self {
26
26
relay : relay_behavior,
27
- gossipsub : create_gossipsub_behavior ( key . clone ( ) ) ,
27
+ gossipsub : create_gossipsub_behavior ( peer_id ) ,
28
28
kademlia : create_kademlia_behavior ( peer_id) ,
29
29
autonat : create_autonat_behavior ( peer_id) ,
30
- identify : create_identify_behavior ( public_key) ,
31
30
dcutr : create_dcutr_behavior ( peer_id) ,
31
+ identify : create_identify_behavior ( public_key) ,
32
32
}
33
33
}
34
34
}
35
35
36
36
/// Configures the Kademlia DHT behavior for the node.
37
37
#[ inline]
38
38
fn create_kademlia_behavior ( local_peer_id : PeerId ) -> kad:: Behaviour < MemoryStore > {
39
- use kad:: { Behaviour , Caching , Config } ;
39
+ use kad:: { Behaviour , Config } ;
40
40
41
41
const QUERY_TIMEOUT_SECS : u64 = 5 * 60 ;
42
42
const RECORD_TTL_SECS : u64 = 30 ;
43
43
44
44
let mut cfg = Config :: new ( DRIA_PROTO_NAME ) ;
45
45
cfg. set_query_timeout ( Duration :: from_secs ( QUERY_TIMEOUT_SECS ) )
46
- . set_record_ttl ( Some ( Duration :: from_secs ( RECORD_TTL_SECS ) ) )
47
- . set_replication_interval ( None )
48
- . set_caching ( Caching :: Disabled )
49
- . set_publication_interval ( None ) ;
46
+ . set_record_ttl ( Some ( Duration :: from_secs ( RECORD_TTL_SECS ) ) ) ;
50
47
51
48
Behaviour :: with_config ( local_peer_id, MemoryStore :: new ( local_peer_id) , cfg)
52
49
}
@@ -85,12 +82,18 @@ fn create_autonat_behavior(local_peer_id: PeerId) -> autonat::Behaviour {
85
82
86
83
/// Configures the Gossipsub behavior for pub/sub messaging across peers.
87
84
#[ inline]
88
- fn create_gossipsub_behavior ( id_keys : Keypair ) -> gossipsub:: Behaviour {
89
- use gossipsub:: { Behaviour , ConfigBuilder , Message , MessageAuthenticity , MessageId } ;
85
+ fn create_gossipsub_behavior ( author : PeerId ) -> gossipsub:: Behaviour {
86
+ use gossipsub:: {
87
+ Behaviour , ConfigBuilder , Message , MessageAuthenticity , MessageId , ValidationMode ,
88
+ } ;
90
89
91
90
/// Message TTL in seconds
92
91
const MESSAGE_TTL_SECS : u64 = 100 ;
93
92
93
+ /// We accept permissive validation mode, meaning that we accept all messages
94
+ /// and check their fields based on whether they exist or not.
95
+ const VALIDATION_MODE : ValidationMode = ValidationMode :: Permissive ;
96
+
94
97
/// Gossip cache TTL in seconds
95
98
const GOSSIP_TTL_SECS : u64 = 100 ;
96
99
@@ -112,14 +115,16 @@ fn create_gossipsub_behavior(id_keys: Keypair) -> gossipsub::Behaviour {
112
115
} ;
113
116
114
117
Behaviour :: new (
115
- MessageAuthenticity :: Signed ( id_keys ) ,
118
+ MessageAuthenticity :: Author ( author ) ,
116
119
ConfigBuilder :: default ( )
117
120
. heartbeat_interval ( Duration :: from_secs ( 10 ) )
118
121
. max_transmit_size ( MAX_TRANSMIT_SIZE ) // 256 KB
119
122
. message_id_fn ( message_id_fn)
120
123
. message_ttl ( Duration :: from_secs ( MESSAGE_TTL_SECS ) )
121
124
. gossip_ttl ( Duration :: from_secs ( GOSSIP_TTL_SECS ) )
122
125
. message_capacity ( MESSAGE_CAPACITY )
126
+ . validation_mode ( VALIDATION_MODE )
127
+ . validate_messages ( )
123
128
. max_ihave_length ( MAX_IHAVE_LENGTH )
124
129
. build ( )
125
130
. expect ( "Valid config" ) , // TODO: better error handling
0 commit comments