}
bool meshlink_join(meshlink_handle_t *mesh, const char *invitation) {
-
+ //TODO: think of a better name for this variable, or of a different way to tokenize the invitation URL.
+ char copy[strlen(invitation) + 1];
+ strcpy(copy, invitation);
// Make sure confbase exists and is accessible.
if(mkdir(mesh->confbase, 0777) && errno != EEXIST) {
// return 1;
//}
- char *slash = strchr(invitation, '/');
+ char *slash = strchr(copy, '/');
if(!slash)
goto invalid;
if(strlen(slash) != 48)
goto invalid;
- char *address = invitation;
+ char *address = copy;
char *port = NULL;
if(*address == '[') {
address++;
fprintf(stderr, "Connected to %s port %s...\n", address, port);
// Tell him we have an invitation, and give him our throw-away key.
- int len = snprintf(invitation, sizeof invitation, "0 ?%s %d.%d\n", b64key, PROT_MAJOR, PROT_MINOR);
- if(len <= 0 || len >= sizeof invitation)
- abort();
if(!sendline(mesh->sock, "0 ?%s %d.%d", b64key, PROT_MAJOR, 1)) {
fprintf(stderr, "Error sending request to %s port %s: %s\n", address, port, strerror(errno));
// Check if the hash of the key he gave us matches the hash in the URL.
char *fingerprint = mesh->line + 2;
char hishash[64];
- if(!sha512(fingerprint, strlen(fingerprint), hishash)) {
+ if(sha512(fingerprint, strlen(fingerprint), hishash)) {
fprintf(stderr, "Could not create hash\n%s\n", mesh->line + 2);
return false;
}
if(!sptps_receive_data(&mesh->sptps, mesh->buffer, mesh->blen))
return false;
+ int len;
+
while((len = recv(mesh->sock, mesh->line, sizeof mesh->line, 0))) {
if(len < 0) {
if(errno == EINTR)