forked from clostra/newnode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
105 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "config.h" | ||
#include "sha1.h" | ||
#include "string.h" | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
|
||
struct config { | ||
byte* injector_swarm; | ||
byte* injector_proxy_swarm; | ||
}; | ||
|
||
static byte* compute_swarm(const char* base, const char* salt) | ||
{ | ||
SHA1_CTX ctx; | ||
SHA1Init(&ctx); | ||
SHA1Update(&ctx, (byte*) base, strlen(base)); | ||
|
||
if (salt) { | ||
SHA1Update(&ctx, (byte*) salt, strlen(salt)); | ||
} | ||
|
||
byte* hash_out = malloc(20); | ||
|
||
SHA1Final(hash_out, &ctx); | ||
|
||
return hash_out; | ||
} | ||
|
||
config* config_new(const char *swarm_salt) | ||
{ | ||
config *c = malloc(sizeof(config)); | ||
|
||
c->injector_swarm = compute_swarm("injectors", swarm_salt); | ||
c->injector_proxy_swarm = compute_swarm("injector proxies", swarm_salt); | ||
|
||
return c; | ||
} | ||
|
||
void config_delete(config *c) | ||
{ | ||
free(c->injector_swarm); | ||
free(c->injector_proxy_swarm); | ||
free(c); | ||
} | ||
|
||
const byte* injector_swarm(config* c) | ||
{ | ||
return c->injector_swarm; | ||
} | ||
|
||
const byte* injector_proxy_swarm(config* c) | ||
{ | ||
return c->injector_proxy_swarm; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef __CONFIG_H__ | ||
#define __CONFIG_H__ | ||
|
||
#include "libutp/utp_types.h" // byte | ||
|
||
typedef struct config config; | ||
|
||
config *config_new(const char *swarm_salt); | ||
void config_delete(config*); | ||
|
||
const byte* injector_swarm(config*); | ||
const byte* injector_proxy_swarm(config*); | ||
|
||
#endif // __CONFIG_H__ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters