@@ -2,7 +2,7 @@ use std::collections::hash_map;
2
2
use std:: hash:: { Hash , Hasher } ;
3
3
use std:: time:: Duration ;
4
4
5
- use eyre:: { eyre, Result } ;
5
+ use eyre:: { eyre, Context , Result } ;
6
6
use libp2p:: identity:: { Keypair , PeerId , PublicKey } ;
7
7
use libp2p:: kad:: store:: MemoryStore ;
8
8
use libp2p:: StreamProtocol ;
@@ -139,28 +139,22 @@ fn create_gossipsub_behavior(author: PeerId) -> Result<gossipsub::Behaviour> {
139
139
} ;
140
140
141
141
// TODO: add data transform here later
142
- let config = match ConfigBuilder :: default ( )
143
- . heartbeat_interval ( Duration :: from_secs ( HEARTBEAT_INTERVAL_SECS ) )
144
- . max_transmit_size ( MAX_TRANSMIT_SIZE )
145
- . message_id_fn ( message_id_fn)
146
- . message_capacity ( MESSAGE_CAPACITY )
147
- . message_ttl ( Duration :: from_secs ( MESSAGE_TTL_SECS ) )
148
- . gossip_ttl ( Duration :: from_secs ( GOSSIP_TTL_SECS ) )
149
- . duplicate_cache_time ( Duration :: from_secs ( DUPLICATE_CACHE_TIME_SECS ) )
150
- . max_ihave_length ( MAX_IHAVE_LENGTH )
151
- . send_queue_size ( MAX_SEND_QUEUE_SIZE )
152
- . validation_mode ( VALIDATION_MODE )
153
- . validate_messages ( )
154
- . build ( )
155
- {
156
- Ok ( config) => config,
157
- Err ( e) => {
158
- return Err ( eyre ! ( "Failed to create gossipsub config: {}" , e) ) ;
159
- }
160
- } ;
161
-
162
- match Behaviour :: new ( MessageAuthenticity :: Author ( author) , config) {
163
- Ok ( behaviour) => Ok ( behaviour) ,
164
- Err ( e) => Err ( eyre ! ( "Failed to create gossipsub behaviour: {}" , e) ) ,
165
- }
142
+ Behaviour :: new (
143
+ MessageAuthenticity :: Author ( author) ,
144
+ ConfigBuilder :: default ( )
145
+ . heartbeat_interval ( Duration :: from_secs ( HEARTBEAT_INTERVAL_SECS ) )
146
+ . max_transmit_size ( MAX_TRANSMIT_SIZE )
147
+ . message_id_fn ( message_id_fn)
148
+ . message_capacity ( MESSAGE_CAPACITY )
149
+ . message_ttl ( Duration :: from_secs ( MESSAGE_TTL_SECS ) )
150
+ . gossip_ttl ( Duration :: from_secs ( GOSSIP_TTL_SECS ) )
151
+ . duplicate_cache_time ( Duration :: from_secs ( DUPLICATE_CACHE_TIME_SECS ) )
152
+ . max_ihave_length ( MAX_IHAVE_LENGTH )
153
+ . send_queue_size ( MAX_SEND_QUEUE_SIZE )
154
+ . validation_mode ( VALIDATION_MODE )
155
+ . validate_messages ( )
156
+ . build ( )
157
+ . wrap_err ( eyre ! ( "Failed to create config" ) ) ?,
158
+ )
159
+ . map_err ( |e| eyre ! ( e) )
166
160
}
0 commit comments