Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Michal Zima
coincer
Commits
9f9cd40f
Commit
9f9cd40f
authored
Aug 19, 2018
by
xpetrak2
Browse files
Entity 'peer' renamed into 'host'
parent
57677421
Changes
7
Hide whitespace changes
Inline
Side-by-side
Makefile.am
View file @
9f9cd40f
...
...
@@ -6,13 +6,13 @@ src_coincerd_SOURCES = \
src/coincerd.c
\
src/configuration.c src/configuration.h
\
src/daemon_messages.h
\
src/hosts.c src/hosts.h
\
src/json_parser.c src/json_parser.h
\
src/linkedlist.c src/linkedlist.h
\
src/log.c src/log.h
\
src/neighbours.c src/neighbours.h
\
src/p2p.c src/p2p.h
\
src/paths.c src/paths.h
\
src/peers.c src/peers.h
src/paths.c src/paths.h
src_coincerd_CFLAGS
=
$(AM_CFLAGS)
$(JANSSON_CFLAGS)
$(LIBEVENT_CFLAGS)
$(LIBSODIUM_CFLAGS)
src_coincerd_LDADD
=
$(AM_LDADD)
$(JANSSON_LIBS)
$(LIBEVENT_LIBS)
$(LIBSODIUM_LIBS)
...
...
src/coincerd.c
View file @
9f9cd40f
...
...
@@ -23,11 +23,11 @@
#include <stdlib.h>
#include <time.h>
#include "hosts.h"
#include "log.h"
#include "neighbours.h"
#include "p2p.h"
#include "paths.h"
#include "peers.h"
static
void
signal_cb
(
evutil_socket_t
fd
,
short
events
,
void
*
ctx
);
static
void
conns_cb
(
evutil_socket_t
fd
,
short
events
,
void
*
ctx
);
...
...
@@ -76,9 +76,9 @@ int main(void)
linkedlist_init
(
&
global_state
.
pending_neighbours
);
linkedlist_init
(
&
global_state
.
neighbours
);
linkedlist_init
(
&
global_state
.
peer
s
);
linkedlist_init
(
&
global_state
.
host
s
);
fetch_
peer
s
(
global_state
.
filepaths
.
peer
s
,
&
global_state
.
peer
s
);
fetch_
host
s
(
global_state
.
filepaths
.
host
s
,
&
global_state
.
host
s
);
/* setup everything needed for TCP listening */
if
(
listen_init
(
&
listener
,
&
global_state
)
!=
0
)
{
...
...
src/
peer
s.c
→
src/
host
s.c
View file @
9f9cd40f
...
...
@@ -22,154 +22,155 @@
#include <stdlib.h>
#include <string.h>
#include "hosts.h"
#include "linkedlist.h"
#include "log.h"
#include "peers.h"
/**
* Delete all
peer
s and their data.
* Delete all
host
s and their data.
*
* @param
peer
s Linkedlist of
peer
s.
* @param
host
s Linkedlist of
host
s.
*/
void
clear_
peer
s
(
linkedlist_t
*
peer
s
)
void
clear_
host
s
(
linkedlist_t
*
host
s
)
{
/*
peer
_t has no dynamically allocated variables */
linkedlist_destroy
(
peer
s
);
/*
host
_t has no dynamically allocated variables */
linkedlist_destroy
(
host
s
);
}
/**
* Fetch
peer
s from file into linkedlist.
* Fetch
host
s from file into linkedlist.
*
* @param
peer
s_path Path to
peer
s file.
* @param
peer
s Fetch loaded
peer
s in here.
* @param
host
s_path Path to
host
s file.
* @param
host
s Fetch loaded
host
s in here.
*
* @return 0 Successfully fetched.
* @return 1
Peer
s file could not be opened.
* @return 1
Host
s file could not be opened.
*/
int
fetch_
peer
s
(
const
char
*
peer
s_path
,
linkedlist_t
*
peer
s
)
int
fetch_
host
s
(
const
char
*
host
s_path
,
linkedlist_t
*
host
s
)
{
struct
in6_addr
addr
;
FILE
*
peer
s_file
;
FILE
*
host
s_file
;
peers_file
=
fopen
(
peers_path
,
"rb"
);
if
(
peers_file
==
NULL
)
{
log_warning
(
"Peers file not found at %"
,
peers_path
);
hosts_file
=
fopen
(
hosts_path
,
"rb"
);
if
(
hosts_file
==
NULL
)
{
log_warn
(
"Hosts file not found at %s. "
"It is safe to ignore this warning"
,
hosts_path
);
return
1
;
}
while
(
fread
(
&
addr
,
sizeof
(
struct
in6_addr
),
1
,
peer
s_file
)
==
1
)
{
save_
peer
(
peer
s
,
&
addr
);
while
(
fread
(
&
addr
,
sizeof
(
struct
in6_addr
),
1
,
host
s_file
)
==
1
)
{
save_
host
(
host
s
,
&
addr
);
}
fclose
(
peer
s_file
);
fclose
(
host
s_file
);
return
0
;
}
/**
* Fetch pointers to
peer
s with specific flags set, into array that is being
* Fetch pointers to
host
s with specific flags set, into array that is being
* allocated in here.
*
* @param
peer
s All
peer
s known to us.
* @param output Output array of pointers to satisfying
peer
s.
* @param
host
s All
host
s known to us.
* @param output Output array of pointers to satisfying
host
s.
* If set to NULL, function just returns
* the number of them.
* @param flags Choose
peer
s based on these flags.
* Fetches output with all known
peer
s if set to 0.
* @param flags Choose
host
s based on these flags.
* Fetches output with all known
host
s if set to 0.
*
* @return >=0 The number of satisfying
peer
s.
* @return >=0 The number of satisfying
host
s.
* @return -1 Allocation failure.
*/
int
fetch_specific_
peer
s
(
const
linkedlist_t
*
peer
s
,
peer
_t
***
output
,
int
fetch_specific_
host
s
(
const
linkedlist_t
*
host
s
,
host
_t
***
output
,
int
flags
)
{
linkedlist_node_t
*
current_node
;
peer
_t
*
current_
peer
;
host
_t
*
current_
host
;
size_t
n
=
0
;
if
(
output
!=
NULL
)
{
*
output
=
(
peer
_t
**
)
malloc
(
linkedlist_size
(
peer
s
)
*
sizeof
(
peer
_t
*
));
*
output
=
(
host
_t
**
)
malloc
(
linkedlist_size
(
host
s
)
*
sizeof
(
host
_t
*
));
if
(
*
output
==
NULL
)
{
log_error
(
"Fetching specific
peer
s"
);
log_error
(
"Fetching specific
host
s"
);
return
-
1
;
}
}
current_node
=
linkedlist_get_first
(
peer
s
);
current_node
=
linkedlist_get_first
(
host
s
);
while
(
current_node
!=
NULL
)
{
current_
peer
=
(
peer
_t
*
)
current_node
->
data
;
/* if all specified flags are being set on this
peer
*/
if
((
current_
peer
->
flags
&
flags
)
==
flags
)
{
current_
host
=
(
host
_t
*
)
current_node
->
data
;
/* if all specified flags are being set on this
host
*/
if
((
current_
host
->
flags
&
flags
)
==
flags
)
{
if
(
output
!=
NULL
)
{
(
*
output
)[
n
++
]
=
current_
peer
;
(
*
output
)[
n
++
]
=
current_
host
;
}
else
{
n
++
;
}
}
current_node
=
linkedlist_get_next
(
peer
s
,
current_node
);
current_node
=
linkedlist_get_next
(
host
s
,
current_node
);
}
return
n
;
}
/**
* Find
peer
in the linkedlist by
their
address.
* Find
host
in the linkedlist by
its
address.
*
* @param
peer
s Linkedlist of
peer
s.
* @param addr Address of the
peer
we want.
* @param
host
s Linkedlist of
host
s.
* @param addr Address of the
host
we want.
*
* @return
peer
_t Requested
peer
.
* @return NULL
Peer
not found.
* @return
host
_t Requested
host
.
* @return NULL
Host
not found.
*/
peer
_t
*
find_
peer_by_addr
(
const
linkedlist_t
*
peer
s
,
const
struct
in6_addr
*
addr
)
host
_t
*
find_
host
(
const
linkedlist_t
*
host
s
,
const
struct
in6_addr
*
addr
)
{
const
linkedlist_node_t
*
current
=
linkedlist_get_first
(
peer
s
);
const
linkedlist_node_t
*
current
=
linkedlist_get_first
(
host
s
);
while
(
current
!=
NULL
)
{
peer
_t
*
current_data
=
(
peer
_t
*
)
current
->
data
;
host
_t
*
current_data
=
(
host
_t
*
)
current
->
data
;
/* ip addresses match => requested
peer
found */
/* ip addresses match => requested
host
found */
if
(
memcmp
(
&
current_data
->
addr
,
addr
,
16
)
==
0
)
{
/* return node's data; struct s_
peer
*/
/* return node's data; struct s_
host
*/
return
current_data
;
}
current
=
linkedlist_get_next
(
peer
s
,
current
);
current
=
linkedlist_get_next
(
host
s
,
current
);
}
/* requested
peer
not found */
/* requested
host
not found */
return
NULL
;
}
/* TODO: allocate memory for the 'output', don't assume any buffer size */
/**
* '\n' separated output string of
peer
addresses in readable form.
* '\n' separated output string of
host
addresses in readable form.
*
* @param
peer
s List of
peer
s.
* @param
host
s List of
host
s.
* @param output Output string.
*/
void
peer
s_to_str
(
const
linkedlist_t
*
peer
s
,
char
*
output
)
void
host
s_to_str
(
const
linkedlist_t
*
host
s
,
char
*
output
)
{
linkedlist_node_t
*
current_node
;
peer
_t
*
current_
peer
;
host
_t
*
current_
host
;
size_t
output_size
=
0
;
char
text_ip
[
INET6_ADDRSTRLEN
];
output
[
0
]
=
'\0'
;
current_node
=
linkedlist_get_first
(
peer
s
);
current_node
=
linkedlist_get_first
(
host
s
);
while
(
current_node
!=
NULL
)
{
current_
peer
=
(
peer
_t
*
)
current_node
->
data
;
current_
host
=
(
host
_t
*
)
current_node
->
data
;
/* binary ip to text ip conversion */
inet_ntop
(
AF_INET6
,
&
current_
peer
->
addr
,
&
current_
host
->
addr
,
text_ip
,
INET6_ADDRSTRLEN
);
output_size
+=
strlen
(
text_ip
);
strcat
(
output
,
text_ip
);
current_node
=
linkedlist_get_next
(
peer
s
,
current_node
);
/* if it's not the last
peer
, append '\n' */
current_node
=
linkedlist_get_next
(
host
s
,
current_node
);
/* if it's not the last
host
, append '\n' */
if
(
current_node
!=
NULL
)
{
output
[
output_size
++
]
=
'\n'
;
}
...
...
@@ -178,166 +179,166 @@ void peers_to_str(const linkedlist_t *peers, char *output)
}
/**
* Save new
peer
into sorted linkedlist of
peer
s.
* Save new
host
into sorted linkedlist of
host
s.
*
* @param
peer
s The linkedlist of
peer
s.
* @param addr Address of the new
peer
.
* @param
host
s The linkedlist of
host
s.
* @param addr Address of the new
host
.
*
* @return
peer
_t Newly saved
peer
.
* @return NULL
Peer
is already saved, default or
* @return
host
_t Newly saved
host
.
* @return NULL
Host
is already saved, default or
* allocation failure.
*/
peer
_t
*
save_
peer
(
linkedlist_t
*
peer
s
,
const
struct
in6_addr
*
addr
)
host
_t
*
save_
host
(
linkedlist_t
*
host
s
,
const
struct
in6_addr
*
addr
)
{
int
cmp_value
;
struct
in6_addr
curr_addr
;
linkedlist_node_t
*
current_node
;
peer
_t
*
current_
peer
;
host
_t
*
current_
host
;
int
i
;
linkedlist_node_t
*
new_node
;
peer
_t
*
new_
peer
;
host
_t
*
new_
host
;
char
text_ip
[
INET6_ADDRSTRLEN
];
/* save
peer
to the list of known
peer
s, unless it's a default
peer
*/
for
(
i
=
0
;
i
<
DEFAULT_
PEER
S_SIZE
;
i
++
)
{
memcpy
(
&
curr_addr
,
DEFAULT_
PEER
S
[
i
],
16
);
/* it's a default
peer
, don't save it into '
peer
s' */
/* save
host
to the list of known
host
s, unless it's a default
host
*/
for
(
i
=
0
;
i
<
DEFAULT_
HOST
S_SIZE
;
i
++
)
{
memcpy
(
&
curr_addr
,
DEFAULT_
HOST
S
[
i
],
16
);
/* it's a default
host
, don't save it into '
host
s' */
if
(
memcmp
(
&
curr_addr
,
addr
,
16
)
==
0
)
{
return
NULL
;
}
}
/* allocate memory for a new
peer
*/
new_
peer
=
(
peer
_t
*
)
malloc
(
sizeof
(
peer
_t
));
if
(
new_
peer
==
NULL
)
{
log_error
(
"Saving new
peer
"
);
/* allocate memory for a new
host
*/
new_
host
=
(
host
_t
*
)
malloc
(
sizeof
(
host
_t
));
if
(
new_
host
==
NULL
)
{
log_error
(
"Saving new
host
"
);
return
NULL
;
}
/* initialize all attributes of the new
peer
*/
memcpy
(
&
new_
peer
->
addr
,
addr
,
16
);
set_
peer
_flags
(
new_
peer
,
PEER
_AVAILABLE
);
/* initialize all attributes of the new
host
*/
memcpy
(
&
new_
host
->
addr
,
addr
,
16
);
set_
host
_flags
(
new_
host
,
HOST
_AVAILABLE
);
/* get textual representation of 'addr' */
inet_ntop
(
AF_INET6
,
addr
,
text_ip
,
INET6_ADDRSTRLEN
);
/* insert 'new_
peer
' to its proper position in the sorted linkedlist;
* start from the last node of '
peer
s', as 'fetch_
peer
s' (using this
/* insert 'new_
host
' to its proper position in the sorted linkedlist;
* start from the last node of '
host
s', as 'fetch_
host
s' (using this
* function) is likely to save in ascending order => better performance
*/
current_node
=
linkedlist_get_last
(
peer
s
);
current_node
=
linkedlist_get_last
(
host
s
);
while
(
current_node
!=
NULL
)
{
current_
peer
=
(
peer
_t
*
)
current_node
->
data
;
current_
host
=
(
host
_t
*
)
current_node
->
data
;
cmp_value
=
memcmp
(
&
new_
peer
->
addr
,
&
current_
peer
->
addr
,
16
);
/* the linkedlist already contains this
peer
*/
cmp_value
=
memcmp
(
&
new_
host
->
addr
,
&
current_
host
->
addr
,
16
);
/* the linkedlist already contains this
host
*/
if
(
cmp_value
==
0
)
{
free
(
new_
peer
);
free
(
new_
host
);
return
NULL
;
}
else
if
(
cmp_value
>
0
)
{
/* the proper position found */
new_node
=
linkedlist_insert_after
(
peer
s
,
new_node
=
linkedlist_insert_after
(
host
s
,
current_node
,
new_
peer
);
new_
host
);
if
(
new_node
!=
NULL
)
{
log_debug
(
"save_
peer
- %s successfully saved"
,
log_debug
(
"save_
host
- %s successfully saved"
,
text_ip
);
}
return
new_
peer
;
return
new_
host
;
}
current_node
=
linkedlist_get_prev
(
peer
s
,
current_node
);
current_node
=
linkedlist_get_prev
(
host
s
,
current_node
);
}
/* the new
peer
's addr is lexicographically the lowest */
new_node
=
linkedlist_insert_after
(
peers
,
&
peer
s
->
first
,
new_
peer
);
/* the new
host
's addr is lexicographically the lowest */
new_node
=
linkedlist_insert_after
(
hosts
,
&
host
s
->
first
,
new_
host
);
if
(
new_node
!=
NULL
)
{
log_debug
(
"save_
peer
- %s successfully saved"
,
text_ip
);
log_debug
(
"save_
host
- %s successfully saved"
,
text_ip
);
}
return
new_
peer
;
return
new_
host
;
}
/**
* Set flags on given
peer
.
* Set flags on given
host
.
*
* @param
peer
Set flags on this
peer
.
* @param flags Set these flags on the
peer
.
* @param
host
Set flags on this
host
.
* @param flags Set these flags on the
host
.
*/
void
set_
peer
_flags
(
peer_t
*
peer
,
int
flags
)
void
set_
host
_flags
(
host_t
*
host
,
int
flags
)
{
peer
->
flags
|=
flags
;
host
->
flags
|=
flags
;
}
/**
* Shuffle an input array of
peer
s.
* Shuffle an input array of
host
s.
*
* @param
peer
s The array of
peer
s to be shuffled.
* @param
peer
s_size The number of
peer
s to be shuffled.
* @param
host
s The array of
host
s to be shuffled.
* @param
host
s_size The number of
host
s to be shuffled.
*/
void
shuffle_
peer
s_arr
(
peer
_t
**
peer
s
,
size_t
peer
s_size
)
void
shuffle_
host
s_arr
(
host
_t
**
host
s
,
size_t
host
s_size
)
{
size_t
i
,
j
;
peer
_t
*
tmp
;
host
_t
*
tmp
;
for
(
i
=
0
;
i
<
peer
s_size
;
i
++
)
{
for
(
i
=
0
;
i
<
host
s_size
;
i
++
)
{
/* don't swap with already swapped;
* swapping
peer
s[i] with
peer
s[j], where j is a random index
* such that j >= i AND j <
peer
s_size
* swapping
host
s[i] with
host
s[j], where j is a random index
* such that j >= i AND j <
host
s_size
*/
j
=
i
+
rand
()
%
(
peer
s_size
-
i
);
j
=
i
+
rand
()
%
(
host
s_size
-
i
);
tmp
=
peer
s
[
i
];
peer
s
[
i
]
=
peer
s
[
j
];
peer
s
[
j
]
=
tmp
;
tmp
=
host
s
[
i
];
host
s
[
i
]
=
host
s
[
j
];
host
s
[
j
]
=
tmp
;
}
}
/**
* Store
peer
s from a linkedlist into a file.
* Store
host
s from a linkedlist into a file.
*
* @param
peer
s_path Path to '
peer
s' file.
* @param
peer
s Linkedlist of the
peer
s to be stored.
* @param
host
s_path Path to '
host
s' file.
* @param
host
s Linkedlist of the
host
s to be stored.
*
* @return 0 Successfully stored.
* @return 1 Failure.
*/
int
store_
peer
s
(
const
char
*
peer
s_path
,
const
linkedlist_t
*
peer
s
)
int
store_
host
s
(
const
char
*
host
s_path
,
const
linkedlist_t
*
host
s
)
{
const
linkedlist_node_t
*
current
;
const
peer
_t
*
current_
peer
;
FILE
*
peer
s_file
;
const
host
_t
*
current_
host
;
FILE
*
host
s_file
;
peer
s_file
=
fopen
(
peer
s_path
,
"wb"
);
if
(
peer
s_file
==
NULL
)
{
log_error
(
"Can not create
peer
s file at %s"
,
peer
s_path
);
host
s_file
=
fopen
(
host
s_path
,
"wb"
);
if
(
host
s_file
==
NULL
)
{
log_error
(
"Can not create
host
s file at %s"
,
host
s_path
);
return
1
;
}
current
=
linkedlist_get_first
(
peer
s
);
current
=
linkedlist_get_first
(
host
s
);
while
(
current
!=
NULL
)
{
current_
peer
=
(
peer
_t
*
)
current
->
data
;
current_
host
=
(
host
_t
*
)
current
->
data
;
/* if fwrite fails, terminate storing */
if
(
fwrite
(
&
current_
peer
->
addr
,
if
(
fwrite
(
&
current_
host
->
addr
,
sizeof
(
struct
in6_addr
),
1
,
peer
s_file
)
!=
1
)
{
log_error
(
"Storing
peer
s"
);
fclose
(
peer
s_file
);
host
s_file
)
!=
1
)
{
log_error
(
"Storing
host
s"
);
fclose
(
host
s_file
);
return
1
;
}
current
=
linkedlist_get_next
(
peer
s
,
current
);
current
=
linkedlist_get_next
(
host
s
,
current
);
}
fclose
(
peer
s_file
);
fclose
(
host
s_file
);
return
0
;
}
/**
* Unset flags on given
peer
.
* Unset flags on given
host
.
*
* @param
peer
Unset flags on this
peer
.
* @param flags Unset these flags on the
peer
.
* @param
host
Unset flags on this
host
.
* @param flags Unset these flags on the
host
.
*/
void
unset_
peer
_flags
(
peer_t
*
peer
,
int
flags
)
void
unset_
host
_flags
(
host_t
*
host
,
int
flags
)
{
peer
->
flags
&=
~
flags
;
host
->
flags
&=
~
flags
;
}
src/
peer
s.h
→
src/
host
s.h
View file @
9f9cd40f
...
...
@@ -16,28 +16,28 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef
PEER
S_H
#define
PEER
S_H
#ifndef
HOST
S_H
#define
HOST
S_H
#include <arpa/inet.h>
#include <stdint.h>
#include "linkedlist.h"
/* number of
peer
s guaranteed to be in the network */
#define DEFAULT_
PEER
S_SIZE 2
/* maximum number of
peer
s we store */
#define MAX_
PEER
S_SIZE 50
/* number of
host
s guaranteed to be in the network */
#define DEFAULT_
HOST
S_SIZE 2
/* maximum number of
host
s we store */
#define MAX_
HOST
S_SIZE 50
/** A
peer
is not available if they is already our neighbour,
/** A
host
is not available if they is already our neighbour,
* pending to become one, or if we are unnable to connect to them.
* 1 if available, 0 if not.
*/
#define
PEER
_AVAILABLE 0x01
#define
HOST
_AVAILABLE 0x01
/* IPv6 addresses of
peer
s guaranteed to be in the network */
static
const
unsigned
char
DEFAULT_
PEER
S
[
DEFAULT_
PEER
S_SIZE
][
16
]
=
{
/* TODO: Replace with real default
peer
s */
/* IPv6 addresses of
host
s guaranteed to be in the network */
static
const
unsigned
char
DEFAULT_
HOST
S
[
DEFAULT_
HOST
S_SIZE
][
16
]
=
{
/* TODO: Replace with real default
host
s */
{
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
0x00
,
...
...
@@ -52,38 +52,38 @@ static const unsigned char DEFAULT_PEERS[DEFAULT_PEERS_SIZE][16] = {
}
};
/**
Peer
info holder. */
typedef
struct
s_
peer
{
/**
Host
info holder. */
typedef
struct
s_
host
{
/** Binary IPv6 address. */
struct
in6_addr
addr
;
/** A set of flags for this
peer
. */
/** A set of flags for this
host
. */
int
flags
;
/* TODO: add uptime */
}
peer
_t
;
}
host
_t
;
void
clear_
peer
s
(
linkedlist_t
*
peer
s
);
void
clear_
host
s
(
linkedlist_t
*
host
s
);
int
fetch_
peer
s
(
const
char
*
peer
s_path
,
linkedlist_t
*
peer
s
);
int
fetch_
host
s
(
const
char
*
host
s_path
,
linkedlist_t
*
host
s
);
int
fetch_specific_
peer
s
(
const
linkedlist_t
*
peer
s
,
peer
_t
***
output
,
int
fetch_specific_
host
s
(
const
linkedlist_t
*
host
s
,
host
_t
***
output
,
int
flags
);
peer
_t
*
find_
peer_by_addr
(
const
linkedlist_t
*
peer
s
,
const
struct
in6_addr
*
addr
);
host
_t
*
find_
host
(
const
linkedlist_t
*
host
s
,
const
struct
in6_addr
*
addr
);
void
peer
s_to_str
(
const
linkedlist_t
*
peer
s
,
char
*
output
);
void
host
s_to_str
(
const
linkedlist_t
*
host
s
,
char
*
output
);
void
reset_
peer
s_availability
(
linkedlist_t
*
peer
s
);
void
reset_
host
s_availability
(
linkedlist_t
*
host
s
);
peer
_t
*
save_
peer
(
linkedlist_t
*
peer
s
,
const
struct
in6_addr
*
addr
);
host
_t
*
save_
host
(
linkedlist_t
*
host
s
,
const
struct
in6_addr
*
addr
);
void
set_
peer
_flags
(
peer_t
*
peer
,
int
flags
);
void
set_
host
_flags
(
host_t
*
host
,
int
flags
);
void
shuffle_
peer
s_arr
(
peer
_t
**
peer
s
,
size_t
peer
s_size
);
void
shuffle_
host
s_arr
(
host
_t
**
host
s
,
size_t
host
s_size
);
int
store_
peer
s
(
const
char
*
peer
s_path
,
const
linkedlist_t
*
peer
s
);
int
store_
host
s
(
const
char
*
host
s_path
,
const
linkedlist_t
*
host
s
);
void
unset_
peer
_flags
(
peer_t
*
peer
,
int
flags
);
void
unset_
host
_flags
(
host_t
*
host
,
int
flags
);
#endif
/*
PEER
S_H */
#endif
/*
HOST
S_H */
src/p2p.c
View file @
9f9cd40f
...
...
@@ -21,20 +21,19 @@
#include <arpa/inet.h>
/* inet_ntop */
#include <assert.h>
#include <errno.h>
#include <event2/listener.h>
#include <event2/bufferevent.h>
#include <event2/buffer.h>
#include <event2/bufferevent.h>
#include <event2/listener.h>
#include <netinet/in.h>
/* sockaddr_in6 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
/* sleep */
#include "hosts.h"
#include "linkedlist.h"
#include "log.h"
#include "neighbours.h"
#include "p2p.h"
#include "peers.h"
/**
* Simple helper for conversion of binary IP to readable IP address.
...
...
@@ -48,7 +47,7 @@ static void ip_to_string(const struct in6_addr *binary_ip, char *ip)
}
/**
* Ask
the
neighbour for a list of addresses.