Skip to content

Commit

Permalink
New directory structure.
Browse files Browse the repository at this point in the history
First connection using SSL successful.
Began work on docs.
  • Loading branch information
Jose Fonseca committed Oct 11, 2020
1 parent 43735ec commit d1604c0
Show file tree
Hide file tree
Showing 31 changed files with 739 additions and 21 deletions.
58 changes: 39 additions & 19 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
# http://www.gnu.org/software/automake

Makefile.in
/ar-lib
/mdate-sh
/py-compile
/test-driver
/ylwrap

# http://www.gnu.org/software/autoconf

autom4te.cache
/autoscan.log
/autoscan-*.log
Expand All @@ -25,25 +20,50 @@ autom4te.cache
/install-sh
/missing
/stamp-h1

# https://www.gnu.org/software/libtool/

/ltmain.sh

# http://www.gnu.org/software/texinfo

/texinfo.tex

# http://www.gnu.org/software/m4/

m4/libtool.m4
m4/ltoptions.m4
m4/ltsugar.m4
m4/ltversion.m4
m4/lt~obsolete.m4

# Generated Makefile
# (meta build system like autotools,
# can automatically generate from config.status script
# (which is called by configure script))
Makefile
/config.h
.deps
bin/
.dirstamp
*.d
*.o
*.ko
*.obj
*.elf
*.ilk
*.map
*.exp
*.gch
*.pch
*.lib
*.a
*.la
*.lo
*.dll
*.so
*.so.*
*.dylib
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
*.dSYM/
*.su
*.idb
*.pdb
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
3 changes: 3 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cavax - A C language implementation of Avalanche AVAX Protocol

Browse cavax Documentation at https://crypto.bi/cavax/
1 change: 1 addition & 0 deletions COPYING
Empty file added ChangeLog
Empty file.
1 change: 1 addition & 0 deletions INSTALL
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Crypto.BI
Copyright (c) 2020 https://crypto.bi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
10 changes: 10 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# https://crypto.bi/cavax/
AUTOMAKE_OPTIONS=subdir-objects
AM_LDFLAGS=
AM_CPPFLAGS = -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
ACLOCAL_AMFLAGS=-I m4
bin_PROGRAMS=bin/cavax
bin_cavax_SOURCES=src/cavax.c src/network/network.c src/network/beacons.c src/network/connect.c src/sys/log.c
bin_cavax_CPPFLAGS = -Wall -Wextra -pedantic-errors -I./include
bin_cavax_LDFLAGS =
bin_cavax_LDADD=-lglib-2.0 -lpthread -lm -lssl -lcrypto
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cavax - A C language implementation of Avalanche AVAX Protocol
3 changes: 3 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cavax - A C language implementation of Avalanche AVAX Protocol

Browse cavax Documentation at https://crypto.bi/cavax/
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# cavax
A C language implementation of Avalanche AVAX Protocol

A C language implementation of [Avalanche AVAX Protocol](https://crypto.bi/category/avax/)

Browse [cavax Documentation](https://crypto.bi/cavax/)
12 changes: 12 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# https://crypto.bi/cavax/

AC_INIT([cavax], [0.1])
AC_CONFIG_SRCDIR([.])
AM_INIT_AUTOMAKE
AC_CONFIG_MACRO_DIRS([m4])
AC_PREREQ([2.69])
AC_CONFIG_HEADERS([config.h])
AC_PROG_CC
AC_CHECK_HEADERS([stdlib.h])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
26 changes: 26 additions & 0 deletions include/cavax/cavax.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef _Z_CAVAX_CAVAX
#define _Z_CAVAX_CAVAX

/*
https://crypto.bi/cavax/
*/

// constants from network/network.go
#define defaultInitialReconnectDelay 1
#define defaultMaxReconnectDelay (60 * 60)
#define DefaultMaxMessageSize (1 << 21)
#define defaultSendQueueSize (1 << 10)
#define defaultMaxNetworkPendingSendBytes (1 << 29) // 512MB
#define defaultNetworkPendingSendBytesToRateLimit (defaultMaxNetworkPendingSendBytes / 4)
#define defaultMaxClockDifference 60
#define defaultPeerListGossipSpacing 60
#define defaultPeerListGossipSize 100
#define defaultPeerListStakerGossipFraction 2
#define defaultGetVersionTimeout 2
#define defaultAllowPrivateIPs true
#define defaultGossipSize 50
#define defaultPingPongTimeout 60
#define defaultPingFrequency (3 * defaultPingPongTimeout / 4)


#endif
10 changes: 10 additions & 0 deletions include/cavax/cavax_general.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef _Z_CAVAX_CAVAX_GENERAL
#define _Z_CAVAX_CAVAX_GENERAL

/*
https://crypto.bi/cavax/
*/

#define COUNT_OF(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))

#endif
19 changes: 19 additions & 0 deletions include/cavax/log.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef _Z_CAVAX_LOG
#define _Z_CAVAX_LOG

/*
https://crypto.bi/cavax/
*/

enum cavax_log_message_type_e {
CAVAX_MESSAGE_INFO,
CAVAX_MESSAGE_ERROR,
CAVAX_MESSAGE_WARNING,
CAVAX_MESSAGE_DEBUG,
};

void cavax_log(const char *msg, enum cavax_log_message_type_e typ);



#endif
27 changes: 27 additions & 0 deletions include/cavax/network/beacon-funcs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef _Z_CAVAX_NETWORK_BEACON_FUNCS
#define _Z_CAVAX_NETWORK_BEACON_FUNCS

/*
https://crypto.bi/cavax/
*/

#include <string.h>
#include <stdint.h>
#include <openssl/ssl.h>
#include <openssl/err.h>

#include "connection.h"
#include "host.h"

void cavax_connect_beacons(struct cavax_host cavax_beacons[], size_t beacon_count, SSL_CTX *ctx);
void cavax_disconnect_beacons(struct cavax_peer_connection cavax_beacons[], size_t beacon_count);

struct cavax_host *cavax_get_random_beacon(void);

/*
Initialize and connect beacons.
*/
void cavax_init_beacons();
void cavax_stop_beacons();

#endif
79 changes: 79 additions & 0 deletions include/cavax/network/beacons.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#ifndef _Z_CAVAX_NETWORK_BEACONS
#define _Z_CAVAX_NETWORK_BEACONS

/*
https://crypto.bi/cavax/
*/


#include <string.h>
#include <stdint.h>
#include <openssl/ssl.h>
#include <openssl/err.h>

#include "host.h"
#include "connect.h"
#include "connection.h"

// IP and ID lists copied from genesis/beacons.go
char *cavax_beacon_ips[] = {
"54.94.43.49:9651",
"52.79.47.77:9651",
"18.229.206.191:9651",
"3.34.221.73:9651",
"13.244.155.170:9651",
"13.244.47.224:9651",
"122.248.200.212:9651",
"52.30.9.211:9651",
"122.248.199.127:9651",
"18.202.190.40:9651",
"15.206.182.45:9651",
"15.207.11.193:9651",
"44.226.118.72:9651",
"54.185.87.50:9651",
"18.158.15.12:9651",
"3.21.38.33:9651",
"54.93.182.129:9651",
"3.128.138.36:9651",
"3.104.107.241:9651",
"3.106.25.139:9651",
"18.162.129.129:9651",
"18.162.161.230:9651",
"52.47.181.114:9651",
"15.188.9.42:9651"
};

char *cavax_beacon_ids[] = {
"NodeID-A6onFGyJjA37EZ7kYHANMR1PFRT8NmXrF",
"NodeID-6SwnPJLH8cWfrJ162JjZekbmzaFpjPcf",
"NodeID-GSgaA47umS1px2ohVjodW9621Ks63xDxD",
"NodeID-BQEo5Fy1FRKLbX51ejqDd14cuSXJKArH2",
"NodeID-Drv1Qh7iJvW3zGBBeRnYfCzk56VCRM2GQ",
"NodeID-DAtCoXfLT6Y83dgJ7FmQg8eR53hz37J79",
"NodeID-FGRoKnyYKFWYFMb6Xbocf4hKuyCBENgWM",
"NodeID-Dw7tuwxpAmcpvVGp9JzaHAR3REPoJ8f2R",
"NodeID-4kCLS16Wy73nt1Zm54jFZsL7Msrv3UCeJ",
"NodeID-9T7NXBFpp8LWCyc58YdKNoowDipdVKAWz",
"NodeID-6ghBh6yof5ouMCya2n9fHzhpWouiZFVVj",
"NodeID-HiFv1DpKXkAAfJ1NHWVqQoojjznibZXHP",
"NodeID-Fv3t2shrpkmvLnvNzcv1rqRKbDAYFnUor",
"NodeID-AaxT2P4uuPAHb7vAD8mNvjQ3jgyaV7tu9",
"NodeID-kZNuQMHhydefgnwjYX1fhHMpRNAs9my1",
"NodeID-A7GwTSd47AcDVqpTVj7YtxtjHREM33EJw",
"NodeID-Hr78Fy8uDYiRYocRYHXp4eLCYeb8x5UuM",
"NodeID-9CkG9MBNavnw7EVSRsuFr7ws9gascDQy3",
"NodeID-A8jypu63CWp76STwKdqP6e9hjL675kdiG",
"NodeID-HsBEx3L71EHWSXaE6gvk2VsNntFEZsxqc",
"NodeID-Nr584bLpGgbCUbZFSBaBz3Xum5wpca9Ym",
"NodeID-QKGoUvqcgormCoMj6yPw9isY7DX9H4mdd",
"NodeID-HCw7S2TVbFPDWNBo1GnFWqJ47f9rDJtt1",
"NodeID-FYv1Lb29SqMpywYXH7yNkcFAzRF2jvm3K"
};

#define CAVAX_BEACON_IP_LEN(bcon) (bcon.port_ptr - bcon.ip_ptr)
#define CAVAX_BEACON_LIST_SIZE (sizeof(cavax_beacon_ips) / sizeof(cavax_beacon_ips[0]))

struct cavax_host cavax_beacons[CAVAX_BEACON_LIST_SIZE];
struct cavax_peer_connection cavax_beacon_connections[CAVAX_BEACON_LIST_SIZE];

#endif
27 changes: 27 additions & 0 deletions include/cavax/network/connect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef _Z_CAVAX_NETWORK_CONNECT
#define _Z_CAVAX_NETWORK_CONNECT

/*
https://crypto.bi/cavax/
*/

#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <openssl/ssl.h>
#include <openssl/err.h>

#include "connection.h"


/*
Connect a socket to host : port and return socket fd.
*/
int cavax_connect(const char *host, uint16_t port);

SSL *cavax_upgrade_connection(int fd, SSL_CTX *ssl_ctx);

int cavax_connect(const char *host, uint16_t port);

#endif
28 changes: 28 additions & 0 deletions include/cavax/network/connection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef _Z_CAVAX_NETWORK_CONNECTION
#define _Z_CAVAX_NETWORK_CONNECTION

/*
https://crypto.bi/cavax/
*/


#include <stdio.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <stdbool.h>

struct cavax_peer_connection {
int fd;
SSL *ssl;
bool responded_version; // mark true if host was live upon connection
};


int cavax_connect(const char *host, uint16_t port);
SSL *cavax_upgrade_connection(int fd, SSL_CTX *ssl_ctx);
void cavax_close_peer_connection(struct cavax_peer_connection *conn);
int cavax_connect(const char *host, uint16_t port);

#endif
18 changes: 18 additions & 0 deletions include/cavax/network/fla.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef _Z_CAVAX_NETWORK_FLA
#define _Z_CAVAX_NETWORK_FLA

/*
https://crypto.bi/cavax/
*/


#include <stdint.h>
#include <stdlib.h>

struct cavax_fixed_length_array {
uint8_t *buf;
size_t len;
};


#endif
Loading

0 comments on commit d1604c0

Please sign in to comment.