@@ -33,22 +33,22 @@ use crate::{
3333#[ cfg( all( not( target_arch = "wasm32" ) , feature = "p2p-webrtc-rs" ) ) ]
3434mod imports {
3535 pub use super :: webrtc_rs:: {
36- build_api, webrtc_signal_send, Api , RTCChannel , RTCConnection , RTCConnectionState ,
37- RTCSignalingError ,
36+ build_api, certificate_from_pem_key , webrtc_signal_send, Api , RTCCertificate , RTCChannel ,
37+ RTCConnection , RTCConnectionState , RTCSignalingError ,
3838 } ;
3939}
4040#[ cfg( all( not( target_arch = "wasm32" ) , feature = "p2p-webrtc-cpp" ) ) ]
4141mod imports {
4242 pub use super :: webrtc_cpp:: {
43- build_api, webrtc_signal_send, Api , RTCChannel , RTCConnection , RTCConnectionState ,
44- RTCSignalingError ,
43+ build_api, certificate_from_pem_key , webrtc_signal_send, Api , RTCCertificate , RTCChannel ,
44+ RTCConnection , RTCConnectionState , RTCSignalingError ,
4545 } ;
4646}
4747#[ cfg( target_arch = "wasm32" ) ]
4848mod imports {
4949 pub use super :: web:: {
50- build_api, webrtc_signal_send, Api , RTCChannel , RTCConnection , RTCConnectionState ,
51- RTCSignalingError ,
50+ build_api, certificate_from_pem_key , webrtc_signal_send, Api , RTCCertificate , RTCChannel ,
51+ RTCConnection , RTCConnectionState , RTCSignalingError ,
5252 } ;
5353}
5454
@@ -140,7 +140,8 @@ pub type OnConnectionStateChangeHdlrFn = Box<
140140
141141pub struct RTCConfig {
142142 pub ice_servers : RTCConfigIceServers ,
143- // TODO(binier): certificate
143+ pub certificate : RTCCertificate ,
144+ pub seed : [ u8 ; 32 ] ,
144145}
145146
146147#[ derive( Serialize ) ]
@@ -223,7 +224,14 @@ async fn wait_for_ice_gathering_complete(pc: &mut RTCConnection) {
223224 }
224225}
225226
226- async fn peer_start ( api : Api , args : PeerAddArgs , abort : Aborted , closed : mpsc:: Sender < ( ) > ) {
227+ async fn peer_start (
228+ api : Api ,
229+ args : PeerAddArgs ,
230+ abort : Aborted ,
231+ closed : mpsc:: Sender < ( ) > ,
232+ certificate : RTCCertificate ,
233+ rng_seed : [ u8 ; 32 ] ,
234+ ) {
227235 let PeerAddArgs {
228236 peer_id,
229237 kind,
@@ -234,6 +242,8 @@ async fn peer_start(api: Api, args: PeerAddArgs, abort: Aborted, closed: mpsc::S
234242
235243 let config = RTCConfig {
236244 ice_servers : Default :: default ( ) ,
245+ certificate,
246+ seed : rng_seed,
237247 } ;
238248 let fut = async {
239249 let mut pc = RTCConnection :: create ( & api, config) . await ?;
@@ -723,11 +733,15 @@ pub trait P2pServiceWebrtc: redux::Service {
723733
724734 fn peers ( & mut self ) -> & mut BTreeMap < PeerId , PeerState > ;
725735
726- fn init < S : TaskSpawner > ( secret_key : SecretKey , spawner : S ) -> P2pServiceCtx {
736+ fn init < S : TaskSpawner > (
737+ secret_key : SecretKey ,
738+ spawner : S ,
739+ rng_seed : [ u8 ; 32 ] ,
740+ ) -> P2pServiceCtx {
727741 const MAX_PEERS : usize = 500 ;
728742 let ( cmd_sender, mut cmd_receiver) = mpsc:: unbounded_channel ( ) ;
729743
730- let _ = secret_key;
744+ let certificate = certificate_from_pem_key ( secret_key. to_pem ( ) . as_str ( ) ) ;
731745
732746 spawner. spawn_main ( "webrtc" , async move {
733747 #[ allow( clippy:: all) ]
@@ -741,6 +755,7 @@ pub trait P2pServiceWebrtc: redux::Service {
741755 let conn_permits = conn_permits. clone ( ) ;
742756 let peer_id = args. peer_id ;
743757 let event_sender = args. event_sender . clone ( ) ;
758+ let certificate = certificate. clone ( ) ;
744759 spawn_local ( async move {
745760 let Ok ( _permit) = conn_permits. try_acquire ( ) else {
746761 // state machine shouldn't allow this to happen.
@@ -755,8 +770,9 @@ pub trait P2pServiceWebrtc: redux::Service {
755770 event_sender_clone ( P2pConnectionEvent :: Closed ( peer_id) . into ( ) ) ;
756771 } ) ;
757772 tokio:: select! {
758- _ = peer_start( api, args, aborted. clone( ) , closed_tx. clone( ) ) => { }
759- _ = aborted. wait( ) => { }
773+ _ = peer_start( api, args, aborted. clone( ) , closed_tx. clone( ) , certificate, rng_seed) => { }
774+ _ = aborted. wait( ) => {
775+ }
760776 }
761777
762778 // delay dropping permit to give some time for cleanup.
0 commit comments