int send_recv(int sock, const char *name) { int to = 100; assert(nn_setsockopt (sock, NN_SOL_SOCKET, NN_RCVTIMEO, &to, sizeof (to)) >= 0); while(1) { recv_name(sock, name); sleep(1); send_name(sock, name); } }
/* Distribute keys */ int distribute_key (void) { int result; golle_num_t temp = golle_num_new (); if (!temp) { fprintf (stderr, "Memory error\n"); return 1; } result = h_to_bin (key.h); if (result != 0) { return result; } /* Send name to opponent */ result = send_name (opponent); if (result != 0) { return result; } /* Receive name from opponent */ result = recv_name (opponent, opponent_name); if (result != 0) { return result; } printf ("Opponent's name is '%s'\n", opponent_name); /* Send h to opponent */ result = send_h (opponent); if (result != 0) { return result; } /* Receive h from opponent */ result = recv_h (opponent, temp); if (result != 0) { return result; } printf ("Received h from %s\n", opponent_name); golle_error err = golle_key_accum_h (&key, temp); if (err != GOLLE_OK) { result = (int)err; fprintf (stderr, "H value accumulation failed.\n"); } golle_bin_clear (&hbin); golle_num_delete (temp); printf ("Key is distributed.\n"); return result; }
int ei_accept_tmo(ei_cnode* ec, int lfd, ErlConnect *conp, unsigned ms) { int fd; struct sockaddr_in cli_addr; int cli_addr_len=sizeof(struct sockaddr_in); unsigned her_version, her_flags; ErlConnect her_name; erl_errno = EIO; /* Default error code */ EI_TRACE_CONN0("ei_accept","<- ACCEPT waiting for connection"); if ((fd = ei_accept_t(lfd, (struct sockaddr*) &cli_addr, &cli_addr_len, ms )) < 0) { EI_TRACE_ERR0("ei_accept","<- ACCEPT socket accept failed"); erl_errno = (fd == -2) ? ETIMEDOUT : EIO; goto error; } EI_TRACE_CONN0("ei_accept","<- ACCEPT connected to remote"); if (recv_name(fd, &her_version, &her_flags, &her_name, ms)) { EI_TRACE_ERR0("ei_accept","<- ACCEPT initial ident failed"); goto error; } if (her_version <= 4) { EI_TRACE_ERR0("ei_accept","<- ACCEPT remote version not compatible"); goto error; } else { unsigned our_challenge; unsigned her_challenge; unsigned char our_digest[16]; if (send_status(fd,"ok", ms)) goto error; our_challenge = gen_challenge(); if (send_challenge(fd, ec->thisnodename, our_challenge, her_version, ms)) goto error; if (recv_challenge_reply(fd, our_challenge, ec->ei_connect_cookie, &her_challenge, ms)) goto error; gen_digest(her_challenge, ec->ei_connect_cookie, our_digest); if (send_challenge_ack(fd, our_digest, ms)) goto error; put_ei_socket_info(fd, her_version, null_cookie, ec); } if (conp) *conp = her_name; EI_TRACE_CONN1("ei_accept","<- ACCEPT (ok) remote = %s",her_name.nodename); erl_errno = 0; /* No error */ return fd; error: EI_TRACE_ERR0("ei_accept","<- ACCEPT failed"); closesocket(fd); return ERL_ERROR; } /* ei_accept */