aboutsummaryrefslogtreecommitdiff
path: root/lib/libostp/session.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libostp/session.c')
-rw-r--r--lib/libostp/session.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/lib/libostp/session.c b/lib/libostp/session.c
index 3843207..b61600f 100644
--- a/lib/libostp/session.c
+++ b/lib/libostp/session.c
@@ -193,6 +193,35 @@ recv_motd(int sockfd, const unsigned char *session_key)
printf("%s\n", buf);
}
+static void
+recv_peers(int sockfd, const unsigned char *session_key)
+{
+ struct peer_block pb;
+ struct peer peer;
+ int i, len;
+
+ memset(&pb, 0, sizeof(pb));
+ memset(&peer, 0, sizeof(peer));
+
+ /* Receive the peer block the server sends back */
+ if ((len = recv_frame(sockfd, sizeof(pb), session_key, &pb)) < 0) {
+ printf("Failed to recv peers...\n");
+ return;
+ }
+
+ printf("Got %d bytes...\n", len);
+ printf("seq=%x\n", pb.seq);
+
+ for (i = 0; i < PB_N_PEERS; ++i) {
+ peer = pb.peers[i];
+ if (peer.pad[0] != 0xFF) {
+ continue;
+ }
+
+ printf("Peer available @ %s:%d\n", peer.host, peer.port);
+ }
+}
+
int
session_new(const char *host, struct ostp_session *res)
{
@@ -233,7 +262,7 @@ session_new(const char *host, struct ostp_session *res)
* Setup the session request and add our public
* key to it. We also assume user authentication.
*/
- stp_sq.options = SESSION_REQ_USER;
+ stp_sq.options = (SESSION_REQ_USER | SESSION_REQ_P2P);
memcpy(stp_sq.pubkey, keypair.pubkey, sizeof(stp_sq.pubkey));
LOG("Sending session request...\n");
@@ -266,6 +295,17 @@ session_new(const char *host, struct ostp_session *res)
return error;
}
+ /*
+ * If we requested P2P, the server will respond
+ * with peer blocks.
+ */
+ if (ISSET(stp_sq.options, SESSION_REQ_P2P)) {
+ recv_peers(sockfd, session_key);
+ free_session_key(session_key);
+ close(sockfd);
+ return 0;
+ }
+
/* Send server SPW bits */
if ((error = client_negotiate_spw(sockfd, session_key)) < 0) {
LOG("Session Parameter Negotiation failed\n");