0.0.002
ddat interop with dat js cable interop with cabal js ddat's frontend = dat-thang cable fe = cable-thang dillo support based on cel's dillo-dat bootstrap node xplatform support Signed-off-by: divo <418@cryspace.space>
This commit is contained in:
1 parent
f0f91540be
commit
b735900f2e
323 files changed
+134347
-343
No files matched your search
@@ -0,0 +1,19 @@
|
||||
#ifndef LIBCESS_COMPAT_H
|
||||
#define LIBCESS_COMPAT_H
|
||||
|
||||
/* Small operating-system spelling adjustments needed by the portable
|
||||
* Cesspool sources. This header has no dependency on Dat or SLEEP. */
|
||||
#ifdef _WIN32
|
||||
#include <direct.h>
|
||||
#include <errno.h>
|
||||
#include <io.h>
|
||||
#include <sys/stat.h>
|
||||
#ifndef mkdir
|
||||
#define mkdir(path, mode) _mkdir(path)
|
||||
#endif
|
||||
#ifndef EKEYREJECTED
|
||||
#define EKEYREJECTED EACCES
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,50 @@
|
||||
#ifndef LIBCESS_NET_H
|
||||
#define LIBCESS_NET_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
typedef SOCKET cess_socket_t;
|
||||
#define CESS_INVALID_SOCKET INVALID_SOCKET
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
typedef int cess_socket_t;
|
||||
#define CESS_INVALID_SOCKET (-1)
|
||||
#endif
|
||||
|
||||
#define CESSNET_PORT 3282
|
||||
#define CESSNET_MAX_PACKET 1400
|
||||
#define CESSNET_TOPIC_BYTES 32
|
||||
#define CESSNET_PEERID_BYTES 32
|
||||
|
||||
typedef struct cess_peer {
|
||||
cess_socket_t fd;
|
||||
struct sockaddr_storage addr;
|
||||
socklen_t addrlen;
|
||||
uint8_t id[CESSNET_PEERID_BYTES];
|
||||
} cess_peer_t;
|
||||
|
||||
typedef struct cessnet {
|
||||
cess_socket_t sock;
|
||||
uint8_t topic[CESSNET_TOPIC_BYTES];
|
||||
uint8_t peerid[CESSNET_PEERID_BYTES];
|
||||
void *context;
|
||||
void (*on_message)(struct cessnet *net, cess_peer_t *peer,
|
||||
const uint8_t *msg, size_t len);
|
||||
} cessnet_t;
|
||||
|
||||
int cessnet_init(cessnet_t *net, const uint8_t topic[CESSNET_TOPIC_BYTES],
|
||||
const uint8_t peerid[CESSNET_PEERID_BYTES]);
|
||||
int cessnet_bind(cessnet_t *net, const char *host, uint16_t port);
|
||||
int cessnet_poll(cessnet_t *net, int timeout_ms);
|
||||
int cessnet_send(cessnet_t *net, const cess_peer_t *peer,
|
||||
const uint8_t *message, size_t length);
|
||||
int cessnet_close(cessnet_t *net);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,129 @@
|
||||
#ifndef LIBCESS_CESSPOOL_H
|
||||
#define LIBCESS_CESSPOOL_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include "cess_net.h"
|
||||
|
||||
#define CESSPOOL_TOPIC_BYTES 32u
|
||||
#define CESSPOOL_PEER_BYTES 32u
|
||||
#define CESSPOOL_MAX_BOOTSTRAP 16u
|
||||
#define CESSPOOL_MAX_PEERS 256u
|
||||
#define CESSPOOL_MAX_TOPICS 64u
|
||||
#define CESSPOOL_MAX_ANNOUNCEMENTS 1024u
|
||||
#define CESSPOOL_MAX_TRANSACTIONS 64u
|
||||
|
||||
typedef struct cesspool_keypair {
|
||||
uint8_t pubkey[32];
|
||||
uint8_t seckey[64];
|
||||
} cesspool_keypair_t;
|
||||
|
||||
enum cesspool_message_type {
|
||||
CESSPOOL_LOOKUP = 0, CESSPOOL_ANNOUNCE = 1, CESSPOOL_UNANNOUNCE = 2,
|
||||
CESSPOOL_REPLY = 3, CESSPOOL_PING = 4, CESSPOOL_PONG = 5,
|
||||
CESSPOOL_HOLEPUNCH = 6
|
||||
};
|
||||
|
||||
typedef struct cesspool_message {
|
||||
uint8_t type, topic[CESSPOOL_TOPIC_BYTES], peer_id[CESSPOOL_PEER_BYTES];
|
||||
uint16_t port;
|
||||
uint8_t payload[2048];
|
||||
size_t payload_len;
|
||||
} cesspool_message_t;
|
||||
typedef struct cesspool_request {
|
||||
uint32_t type;
|
||||
uint16_t port;
|
||||
uint8_t local_address[6];
|
||||
size_t local_address_len;
|
||||
} cesspool_request_t;
|
||||
typedef struct cesspool_response {
|
||||
uint8_t peers[1024]; size_t peers_len;
|
||||
uint8_t local_peers[1024]; size_t local_peers_len;
|
||||
uint8_t peer_info[2048]; size_t peer_info_len;
|
||||
} cesspool_response_t;
|
||||
typedef struct cesspool_peer {
|
||||
cess_peer_t address;
|
||||
uint8_t public_key[32];
|
||||
uint8_t discovery_topic[CESSPOOL_TOPIC_BYTES];
|
||||
uint64_t last_seen;
|
||||
unsigned failures;
|
||||
int local, discovered;
|
||||
} cesspool_peer_t;
|
||||
typedef struct cesspool_topic {
|
||||
uint8_t key[32]; uint16_t port; int announcing, looking_up; uint64_t refresh_at;
|
||||
} cesspool_topic_t;
|
||||
typedef struct cesspool_transaction {
|
||||
uint16_t id; uint8_t target[32], type; uint64_t expires_at; int active;
|
||||
} cesspool_transaction_t;
|
||||
typedef struct cesspool_announcement {
|
||||
uint8_t topic[CESSPOOL_TOPIC_BYTES], peer_id[CESSPOOL_PEER_BYTES];
|
||||
cess_peer_t address;
|
||||
uint64_t last_seen;
|
||||
} cesspool_announcement_t;
|
||||
struct cesspool;
|
||||
typedef void (*cesspool_transport_packet_fn)(struct cesspool *,
|
||||
const cess_peer_t *,
|
||||
const uint8_t *, size_t);
|
||||
typedef struct cesspool {
|
||||
cessnet_t net;
|
||||
cess_peer_t bootstrap_nodes[CESSPOOL_MAX_BOOTSTRAP];
|
||||
size_t bootstrap_count;
|
||||
uint16_t port;
|
||||
int ready, bootstrap_server;
|
||||
cesspool_peer_t peers[CESSPOOL_MAX_PEERS]; size_t peer_count;
|
||||
cesspool_topic_t topics[CESSPOOL_MAX_TOPICS]; size_t topic_count;
|
||||
cesspool_announcement_t announcements[CESSPOOL_MAX_ANNOUNCEMENTS];
|
||||
size_t announcement_count;
|
||||
uint64_t bootstrap_last_seen, bootstrap_probe_at;
|
||||
int bootstrap_reachable;
|
||||
cesspool_transaction_t transactions[CESSPOOL_MAX_TRANSACTIONS];
|
||||
uint16_t next_transaction;
|
||||
void (*on_peer)(struct cesspool *, const cesspool_peer_t *);
|
||||
void (*on_holepunch)(struct cesspool *, const cess_peer_t *);
|
||||
cesspool_transport_packet_fn on_transport_packet;
|
||||
void *transport_context;
|
||||
} cesspool_t;
|
||||
|
||||
int cesspool_identity_init(void);
|
||||
int cesspool_identity_generate(cesspool_keypair_t *identity);
|
||||
int cesspool_identity_save(const char *path, const cesspool_keypair_t *identity);
|
||||
int cesspool_identity_load(const char *path, cesspool_keypair_t *identity);
|
||||
int cesspool_discovery_key(const uint8_t public_key[32], uint8_t topic[32]);
|
||||
int cesspool_encode(const cesspool_message_t *, uint8_t *, size_t, size_t *);
|
||||
int cesspool_decode(cesspool_message_t *, const uint8_t *, size_t);
|
||||
int cesspool_request_encode(const cesspool_request_t *, uint8_t *, size_t, size_t *);
|
||||
int cesspool_request_decode(cesspool_request_t *, const uint8_t *, size_t);
|
||||
int cesspool_response_encode(const cesspool_response_t *, uint8_t *, size_t, size_t *);
|
||||
int cesspool_response_decode(cesspool_response_t *, const uint8_t *, size_t);
|
||||
int cesspool_process_response(cesspool_t *, const cesspool_response_t *, const uint8_t[2]);
|
||||
int cesspool_init(cesspool_t *, const uint8_t peer_id[32]);
|
||||
int cesspool_add_bootstrap(cesspool_t *, const char *, uint16_t);
|
||||
int cesspool_configure_bootstraps(cesspool_t *);
|
||||
int cesspool_bootstrap_config_add(const char *);
|
||||
int cesspool_bootstrap_config_set(const char *);
|
||||
int cesspool_bootstrap_config_get(char *, size_t);
|
||||
int cesspool_bootstrap_config_list(char *, size_t);
|
||||
int cesspool_bootstrap(cesspool_t *);
|
||||
int cesspool_listen(cesspool_t *, const char *, uint16_t);
|
||||
int cesspool_set_bootstrap_server(cesspool_t *, int);
|
||||
int cesspool_announce(cesspool_t *, const uint8_t[32], uint16_t);
|
||||
int cesspool_lookup(cesspool_t *, const uint8_t[32]);
|
||||
int cesspool_unannounce(cesspool_t *, const uint8_t[32], uint16_t);
|
||||
int cesspool_ping(cesspool_t *, const cess_peer_t *);
|
||||
int cesspool_holepunch(cesspool_t *, const cess_peer_t *);
|
||||
int cesspool_poll(cesspool_t *, int);
|
||||
int cesspool_add_peer(cesspool_t *, const cesspool_peer_t *);
|
||||
int cesspool_remove_peer(cesspool_t *, const uint8_t[32]);
|
||||
cesspool_peer_t *cesspool_find_peer(cesspool_t *, const uint8_t[32]);
|
||||
int cesspool_join(cesspool_t *, const uint8_t[32], uint16_t, int, int);
|
||||
int cesspool_leave(cesspool_t *, const uint8_t[32]);
|
||||
int cesspool_tick(cesspool_t *, uint64_t);
|
||||
size_t cesspool_closest(cesspool_t *, const uint8_t[32], cesspool_peer_t **, size_t);
|
||||
size_t cesspool_topic_peers(cesspool_t *, const uint8_t[CESSPOOL_TOPIC_BYTES], cesspool_peer_t **, size_t);
|
||||
size_t cesspool_announced_peer_count(const cesspool_t *);
|
||||
size_t cesspool_announced_topic_count(const cesspool_t *);
|
||||
int cesspool_transaction_begin(cesspool_t *, uint8_t, const uint8_t[32], uint64_t, uint16_t *);
|
||||
int cesspool_transaction_finish(cesspool_t *, uint16_t);
|
||||
int cesspool_destroy(cesspool_t *);
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user