- // Atomically rename the invitation file
- if(rename(filename, usedname)) {
- if(errno == ENOENT) {
- logger(mesh, MESHLINK_ERROR, "Peer %s tried to use non-existing invitation %s\n", c->name, cookie);
- } else {
- logger(mesh, MESHLINK_ERROR, "Error trying to rename invitation %s\n", cookie);
- }
-
- return false;
- }
-
- // Open the renamed file
- FILE *f = fopen(usedname, "r");
-
- if(!f) {
- logger(mesh, MESHLINK_ERROR, "Error trying to open invitation %s\n", cookie);
- unlink(usedname);
- return false;
- }
-
- // Check the timestamp
- struct stat st;
-
- if(fstat(fileno(f), &st)) {
- logger(mesh, MESHLINK_ERROR, "Could not stat invitation file %s\n", usedname);
- fclose(f);
- unlink(usedname);
- return false;
- }
-
- if(time(NULL) > st.st_mtime + mesh->invitation_timeout) {
- logger(mesh, MESHLINK_ERROR, "Peer %s tried to use an outdated invitation file %s\n", c->name, usedname);
- fclose(f);
- unlink(usedname);
+ if(!invitation_read(mesh, "current", cookie, &config, mesh->config_key)) {
+ logger(mesh, MESHLINK_ERROR, "Error while trying to read invitation file\n");