More swarm changes
This commit is contained in:
parent
08a02f7956
commit
03a4b412dd
6 changed files with 20 additions and 16 deletions
|
@ -23,7 +23,7 @@ struct TransportDialer* libp2p_conn_tcp_transport_dialer_new();
|
||||||
* @param private_key the local private key
|
* @param private_key the local private key
|
||||||
* @returns a new Dialer struct
|
* @returns a new Dialer struct
|
||||||
*/
|
*/
|
||||||
struct Dialer* libp2p_conn_dialer_new(struct Libp2pPeer* peer, struct Peerstore* peerstore, struct PrivateKey* private_key) {
|
struct Dialer* libp2p_conn_dialer_new(struct Libp2pPeer* peer, struct Peerstore* peerstore, struct RsaPrivateKey* rsa_private_key) {
|
||||||
int success = 0;
|
int success = 0;
|
||||||
struct Dialer* dialer = (struct Dialer*)malloc(sizeof(struct Dialer));
|
struct Dialer* dialer = (struct Dialer*)malloc(sizeof(struct Dialer));
|
||||||
if (dialer != NULL) {
|
if (dialer != NULL) {
|
||||||
|
@ -33,6 +33,7 @@ struct Dialer* libp2p_conn_dialer_new(struct Libp2pPeer* peer, struct Peerstore*
|
||||||
if (dialer->peer_id != NULL) {
|
if (dialer->peer_id != NULL) {
|
||||||
strncpy(dialer->peer_id, peer->id, peer->id_size);
|
strncpy(dialer->peer_id, peer->id, peer->id_size);
|
||||||
// convert private key to rsa private key
|
// convert private key to rsa private key
|
||||||
|
/*
|
||||||
struct RsaPrivateKey* rsa_private_key = libp2p_crypto_rsa_rsa_private_key_new();
|
struct RsaPrivateKey* rsa_private_key = libp2p_crypto_rsa_rsa_private_key_new();
|
||||||
if (!libp2p_crypto_encoding_x509_der_to_private_key(private_key->data, private_key->data_size, rsa_private_key)) {
|
if (!libp2p_crypto_encoding_x509_der_to_private_key(private_key->data, private_key->data_size, rsa_private_key)) {
|
||||||
libp2p_crypto_rsa_rsa_private_key_free(rsa_private_key);
|
libp2p_crypto_rsa_rsa_private_key_free(rsa_private_key);
|
||||||
|
@ -44,10 +45,11 @@ struct Dialer* libp2p_conn_dialer_new(struct Libp2pPeer* peer, struct Peerstore*
|
||||||
libp2p_conn_dialer_free(dialer);
|
libp2p_conn_dialer_free(dialer);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
dialer->private_key = rsa_private_key;
|
dialer->private_key = rsa_private_key;
|
||||||
//TODO: build transport dialers
|
//TODO: build transport dialers
|
||||||
dialer->transport_dialers = NULL;
|
dialer->transport_dialers = NULL;
|
||||||
dialer->fallback_dialer = libp2p_conn_tcp_transport_dialer_new(dialer->peer_id, private_key);
|
dialer->fallback_dialer = libp2p_conn_tcp_transport_dialer_new(dialer->peer_id, rsa_private_key);
|
||||||
return dialer;
|
return dialer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ struct Stream* libp2p_conn_tcp_dial(const struct TransportDialer* transport_dial
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TransportDialer* libp2p_conn_tcp_transport_dialer_new(char* peer_id, struct PrivateKey* private_key) {
|
struct TransportDialer* libp2p_conn_tcp_transport_dialer_new(char* peer_id, struct RsaPrivateKey* private_key) {
|
||||||
struct TransportDialer* out = libp2p_conn_transport_dialer_new(peer_id, private_key);
|
struct TransportDialer* out = libp2p_conn_transport_dialer_new(peer_id, private_key);
|
||||||
out->can_handle = libp2p_conn_tcp_can_handle;
|
out->can_handle = libp2p_conn_tcp_can_handle;
|
||||||
out->dial = libp2p_conn_tcp_dial;
|
out->dial = libp2p_conn_tcp_dial;
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "libp2p/crypto/key.h"
|
#include "libp2p/crypto/rsa.h"
|
||||||
#include "libp2p/conn/transport_dialer.h"
|
#include "libp2p/conn/transport_dialer.h"
|
||||||
|
|
||||||
struct TransportDialer* libp2p_conn_transport_dialer_new(char* peer_id, struct PrivateKey* private_key) {
|
struct TransportDialer* libp2p_conn_transport_dialer_new(char* peer_id, struct RsaPrivateKey* private_key) {
|
||||||
struct TransportDialer* out = (struct TransportDialer*)malloc(sizeof(struct TransportDialer));
|
struct TransportDialer* out = (struct TransportDialer*)malloc(sizeof(struct TransportDialer));
|
||||||
if (out != NULL) {
|
if (out != NULL) {
|
||||||
out->peer_id = malloc(strlen(peer_id) + 1);
|
out->peer_id = malloc(strlen(peer_id) + 1);
|
||||||
strcpy(out->peer_id, peer_id);
|
strcpy(out->peer_id, peer_id);
|
||||||
if (private_key != NULL) {
|
if (private_key != NULL) {
|
||||||
out->private_key = (struct PrivateKey*)malloc(sizeof(struct PrivateKey));
|
out->private_key = private_key;
|
||||||
libp2p_crypto_private_key_copy(private_key, out->private_key);
|
|
||||||
} else {
|
} else {
|
||||||
out->private_key = NULL;
|
out->private_key = NULL;
|
||||||
}
|
}
|
||||||
|
@ -26,7 +25,7 @@ void libp2p_conn_transport_dialer_free(struct TransportDialer* in) {
|
||||||
if (in != NULL) {
|
if (in != NULL) {
|
||||||
if (in->peer_id != NULL)
|
if (in->peer_id != NULL)
|
||||||
free(in->peer_id);
|
free(in->peer_id);
|
||||||
libp2p_crypto_private_key_free(in->private_key);
|
//libp2p_crypto_private_key_free(in->private_key);
|
||||||
free(in);
|
free(in);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ struct Dialer {
|
||||||
* @param private_key the local private key
|
* @param private_key the local private key
|
||||||
* @returns a new Dialer struct
|
* @returns a new Dialer struct
|
||||||
*/
|
*/
|
||||||
struct Dialer* libp2p_conn_dialer_new(struct Libp2pPeer* peer, struct Peerstore* peerstore, struct PrivateKey* private_key);
|
struct Dialer* libp2p_conn_dialer_new(struct Libp2pPeer* peer, struct Peerstore* peerstore, struct RsaPrivateKey* private_key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* free resources from the Dialer struct
|
* free resources from the Dialer struct
|
||||||
|
|
|
@ -6,12 +6,12 @@
|
||||||
|
|
||||||
struct TransportDialer {
|
struct TransportDialer {
|
||||||
char* peer_id;
|
char* peer_id;
|
||||||
struct PrivateKey* private_key;
|
struct RsaPrivateKey* private_key;
|
||||||
int (*can_handle)(const struct MultiAddress* multiaddr);
|
int (*can_handle)(const struct MultiAddress* multiaddr);
|
||||||
struct Stream* (*dial)(const struct TransportDialer* transport_dialer, const struct MultiAddress* multiaddr);
|
struct Stream* (*dial)(const struct TransportDialer* transport_dialer, const struct MultiAddress* multiaddr);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TransportDialer* libp2p_conn_transport_dialer_new(char* peer_id, struct PrivateKey* private_key);
|
struct TransportDialer* libp2p_conn_transport_dialer_new(char* peer_id, struct RsaPrivateKey* private_key);
|
||||||
void libp2p_conn_transport_dialer_free(struct TransportDialer* in);
|
void libp2p_conn_transport_dialer_free(struct TransportDialer* in);
|
||||||
|
|
||||||
struct Stream* libp2p_conn_transport_dialer_get(const struct Libp2pLinkedList* transport_dialers, const struct MultiAddress* multiaddr);
|
struct Stream* libp2p_conn_transport_dialer_get(const struct Libp2pLinkedList* transport_dialers, const struct MultiAddress* multiaddr);
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
int test_dialer_new() {
|
int test_dialer_new() {
|
||||||
int retVal = 0;
|
int retVal = 0;
|
||||||
char* peer_id = "QmQSDGgxSVTkHmtT25rTzQtc5C1Yg8SpGK3BTws8YsJ4x3";
|
char* peer_id = "QmQSDGgxSVTkHmtT25rTzQtc5C1Yg8SpGK3BTws8YsJ4x3";
|
||||||
struct PrivateKey* private_key = NULL;
|
struct RsaPrivateKey* private_key = NULL;
|
||||||
struct Libp2pPeer* peer = libp2p_peer_new();
|
struct Libp2pPeer* peer = libp2p_peer_new();
|
||||||
peer->id = malloc(strlen(peer_id)+1);
|
peer->id = malloc(strlen(peer_id)+1);
|
||||||
strcpy(peer->id, peer_id);
|
strcpy(peer->id, peer_id);
|
||||||
|
@ -75,7 +75,8 @@ int test_dialer_join_swarm() {
|
||||||
char* orig_peer_id = "QmRKm1d9kSCRpMFtLYpfhhCQ3DKuSSPJa3qn9wWXfwnWnY";
|
char* orig_peer_id = "QmRKm1d9kSCRpMFtLYpfhhCQ3DKuSSPJa3qn9wWXfwnWnY";
|
||||||
char* remote_peer_id = "QmRjLCELimPe7aUdYRVNLD7UmB1CiJdJf8HLovKAB4KwmA";
|
char* remote_peer_id = "QmRjLCELimPe7aUdYRVNLD7UmB1CiJdJf8HLovKAB4KwmA";
|
||||||
size_t orig_peer_id_size = strlen(orig_peer_id);
|
size_t orig_peer_id_size = strlen(orig_peer_id);
|
||||||
struct PrivateKey* private_key = NULL;
|
struct RsaPrivateKey* rsa_private_key = NULL;
|
||||||
|
struct PrivateKey* priv = NULL;
|
||||||
size_t decode_base64_size = 0;
|
size_t decode_base64_size = 0;
|
||||||
uint8_t* decode_base64 = NULL;
|
uint8_t* decode_base64 = NULL;
|
||||||
struct Libp2pPeer* local_peer = NULL;
|
struct Libp2pPeer* local_peer = NULL;
|
||||||
|
@ -93,9 +94,11 @@ int test_dialer_join_swarm() {
|
||||||
if (!libp2p_crypto_encoding_base64_decode((unsigned char*)orig_priv_key, strlen(orig_priv_key), &decode_base64[0], decode_base64_size, &decode_base64_size))
|
if (!libp2p_crypto_encoding_base64_decode((unsigned char*)orig_priv_key, strlen(orig_priv_key), &decode_base64[0], decode_base64_size, &decode_base64_size))
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
if (!libp2p_crypto_private_key_protobuf_decode(decode_base64, decode_base64_size, &private_key))
|
if (!libp2p_crypto_private_key_protobuf_decode(decode_base64, decode_base64_size, &priv))
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
|
//TODO turn PrivateKey into RsaPrivateKey
|
||||||
|
|
||||||
// 2) make the local peer
|
// 2) make the local peer
|
||||||
local_peer = libp2p_peer_new();
|
local_peer = libp2p_peer_new();
|
||||||
local_peer->id = orig_peer_id;
|
local_peer->id = orig_peer_id;
|
||||||
|
@ -104,7 +107,7 @@ int test_dialer_join_swarm() {
|
||||||
peerstore = libp2p_peerstore_new(local_peer);
|
peerstore = libp2p_peerstore_new(local_peer);
|
||||||
|
|
||||||
// 3) make the dialer
|
// 3) make the dialer
|
||||||
dialer = libp2p_conn_dialer_new(local_peer, peerstore, private_key);
|
dialer = libp2p_conn_dialer_new(local_peer, peerstore, rsa_private_key);
|
||||||
|
|
||||||
// 4) make the remote peer
|
// 4) make the remote peer
|
||||||
remote_ma = multiaddress_new_from_string(remote_swarm);
|
remote_ma = multiaddress_new_from_string(remote_swarm);
|
||||||
|
@ -126,7 +129,7 @@ int test_dialer_join_swarm() {
|
||||||
libp2p_peer_free(local_peer);
|
libp2p_peer_free(local_peer);
|
||||||
libp2p_peerstore_free(peerstore);
|
libp2p_peerstore_free(peerstore);
|
||||||
libp2p_conn_dialer_free(dialer);
|
libp2p_conn_dialer_free(dialer);
|
||||||
libp2p_crypto_private_key_free(private_key);
|
libp2p_crypto_private_key_free(priv);
|
||||||
return retVal;
|
return retVal;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue