41 #define DATA_HOST_FREQ \
42 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
47 #define DATA_HOST_CLEAN_FREQ \
48 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 60)
175 _ (
"Removing expired address of transport `%s'\n"),
196 unsigned int *cnt = cls;
241 "Notifying all clients about peer `%s'\n",
299 "Read %d bytes from `%s'\n",
302 if ((size_total < 0) ||
306 _ (
"Failed to parse HELLO in file `%s': %s\n"),
308 "File has invalid size");
309 if ((
GNUNET_YES == unlink_garbage) && (0 != unlink (fn)) &&
316 while (read_pos < (
size_t) size_total)
320 if ((0 == size_hello) || (((
size_t) size_total) - read_pos < size_hello))
323 _ (
"Failed to parse HELLO in file `%s'\n"),
327 if ((
GNUNET_YES == unlink_garbage) && (0 != unlink (fn)) &&
333 if ((
GNUNET_YES == unlink_garbage) && (0 != truncate (fn, read_pos)) &&
345 if (NULL == hello_clean)
348 _ (
"Failed to parse HELLO in file `%s'\n"),
350 if ((
GNUNET_YES == unlink_garbage) && (0 != unlink (fn)) &&
369 if (NULL == r->
hello)
370 r->
hello = hello_clean;
375 r->
hello = hello_clean;
389 read_pos += size_hello;
395 if ((
GNUNET_YES == unlink_garbage) && (0 != unlink (fn)))
399 "Found `%s' and `%s' HELLO message in file\n",
400 (NULL != r->
hello) ?
"public" :
"NON-public",
423 "Adding new peer `%s'\n",
464 if (0 == unlink (fullname))
468 "File `%s' in directory `%s' does not match naming convention. Removed.\n"),
580 "Updating peer `%s' public HELLO \n",
588 "Updating peer `%s' friend only HELLO \n",
606 static unsigned int retries;
624 _ (
"Scanning directory `%s'\n"),
629 if ((0 == dsc.
matched) && (0 == (++retries & 31)))
631 _ (
"Still no peers found in `%s'!\n"),
656 if (NULL != friend_hello)
693 int friend_hello_type;
695 int store_friend_hello;
704 "Updating %s HELLO for `%s'\n",
705 (
GNUNET_YES == friend_hello_type) ?
"friend-only" :
"public",
731 "No change in %s HELLO for `%s'\n",
732 (
GNUNET_YES == friend_hello_type) ?
"friend-only" :
"public",
750 if (NULL != host->
hello)
762 if (NULL != host->
hello)
821 "Stored %s %s HELLO in %s with total size %u\n",
822 (
GNUNET_YES == store_friend_hello) ?
"friend-only" :
"",
878 "Sending public HELLO with size %u for peer `%s'\n",
890 "Sending friend-only HELLO with size %u for peer `%s'\n",
898 "Adding no HELLO for peer `%s'\n",
922 unsigned int cur_hello_size;
923 unsigned int new_hello_size;
943 if (0 != unlink (fn))
954 while (read_pos < read_size)
959 if (0 == cur_hello_size)
962 if (0 != unlink (fn))
973 if (NULL != new_hello)
978 if ((NULL != new_hello) && (0 < cnt))
982 GNUNET_memcpy (&writebuffer[write_pos], new_hello, new_hello_size);
983 write_pos += new_hello_size;
985 read_pos += cur_hello_size;
1001 else if (0 != unlink (fn))
1027 _ (
"Cleaning up directory `%s'\n"),
1072 "HELLO message received for peer `%s'\n",
1095 "GET message received for peer `%s'\n",
1288 "USE_INCLUDED_HELLOS");
1322 _ (
"Importing HELLOs from `%s'\n"),
1335 _ (
"Skipping import of included HELLOs\n"));
struct GNUNET_MQ_Handle * mq
struct GNUNET_MessageHeader * msg
struct GNUNET_MQ_Envelope * env
#define gettext_noop(String)
static char * expiration
Credential TTL.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
static char * address
GNS address for this phone.
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
static struct GNUNET_PEERINFO_NotifyContext * notify
Handle to the peerinfo notify service (NULL until we've connected to it).
struct GNUNET_HashCode key
The key used in the DHT.
static int get
Get DID Documement for DID Flag.
static char * value
Value of the record to add/remove.
static int include_friend_only
Option '-f'.
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
static char * networkIdDirectory
Directory where the hellos are stored in (peerinfo/)
static void handle_notify(void *cls, const struct NotifyMessage *nm)
Handle NOTIFY-message.
static struct InfoMessage * make_info_message(const struct HostEntry *he, int include_friend_only)
Notify all clients in the notify list about the given host entry changing.
static void handle_get(void *cls, const struct ListPeerMessage *lpm)
Handle GET-message.
static void cron_clean_data_hosts(void *cls)
Call this method periodically to scan peerinfo/ for ancient HELLOs to expire.
static struct GNUNET_SCHEDULER_Task * cron_scan
Handle for task to run cron_scan_directory_data_hosts()
#define DATA_HOST_CLEAN_FREQ
How often do we discard old entries in data/hosts/?
static int discard_hosts_helper(void *cls, const char *fn)
delete expired HELLO entries in directory
static int hosts_directory_scan_callback(void *cls, const char *fullname)
Function that is called on each HELLO file in a particular directory.
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
static int check_hello(void *cls, const struct GNUNET_HELLO_Message *hello)
Check HELLO-message.
static struct GNUNET_NotificationContext * notify_list
Clients to immediately notify about all changes.
static void notify_all(struct HostEntry *entry)
Broadcast information about the given entry to all clients that care.
static void shutdown_task(void *cls)
Clean up our state.
static struct GNUNET_HELLO_Message * update_friend_hello(const struct GNUNET_HELLO_Message *hello, const struct GNUNET_HELLO_Message *friend_hello)
Update the HELLO of a friend by merging the addresses.
static int free_host_entry(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Release memory taken by a host entry.
static void cron_scan_directory_data_hosts(void *cls)
Call this method periodically to scan data/hosts for new hosts.
static char * get_host_filename(const struct GNUNET_PeerIdentity *id)
Get the filename under which we would store the GNUNET_HELLO_Message for the given host and protocol.
static int add_to_tc(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Do transmit info about peer to given host.
static void read_host_file(const char *fn, int unlink_garbage, struct ReadHostFileContext *r)
Try to read the HELLOs in the given filename and discard expired addresses.
static void update_hello(const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello)
Bind a host address (hello) to a hostId.
GNUNET_SERVICE_MAIN("peerinfo", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_var_size(hello, GNUNET_MESSAGE_TYPE_HELLO, struct GNUNET_HELLO_Message, NULL), GNUNET_MQ_hd_fixed_size(get, GNUNET_MESSAGE_TYPE_PEERINFO_GET, struct ListPeerMessage, NULL), GNUNET_MQ_hd_fixed_size(get_all, GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL, struct ListAllPeersMessage, NULL), GNUNET_MQ_hd_fixed_size(notify, GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY, struct NotifyMessage, NULL), GNUNET_MQ_handler_end())
Define "main" method using service macro.
static void remove_garbage(const char *fullname)
Remove a file that should not be there.
static int count_addresses(void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
Address iterator that counts the remaining addresses.
static struct HostEntry * add_host_to_known_hosts(const struct GNUNET_PeerIdentity *identity)
Add a host to the list and notify clients about this event.
static struct GNUNET_NotificationContext * notify_friend_only_list
Clients to immediately notify about all changes, even for friend-only HELLOs.
static int discard_expired(void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
Address iterator that causes expired entries to be discarded.
static void * client_connect_cb(void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq)
Client connect callback.
static struct GNUNET_SCHEDULER_Task * cron_clean
Handle for task to run cron_clean_data_hosts()
static void client_disconnect_cb(void *cls, struct GNUNET_SERVICE_Client *client, void *app_ctx)
Client disconnect callback.
static void handle_hello(void *cls, const struct GNUNET_HELLO_Message *hello)
Handle HELLO-message.
static struct GNUNET_CONTAINER_MultiPeerMap * hostmap
The in-memory list of known hosts, mapping of host IDs to 'struct HostEntry*' values.
static void handle_get_all(void *cls, const struct ListAllPeersMessage *lapm)
Handle GET-ALL-message.
#define DATA_HOST_FREQ
How often do we scan the HOST_DIR for new entries?
static void run(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_SERVICE_Handle *service)
Start up peerinfo service.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
Helper library for handling HELLOs.
Constants for network protocols.
API to create, modify and access statistics.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
enum GNUNET_GenericReturnValue GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
enum GNUNET_GenericReturnValue GNUNET_DISK_fn_write(const char *fn, const void *buf, size_t buf_size, enum GNUNET_DISK_AccessPermissions mode)
Write a buffer to a file atomically.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create(const char *dir)
Implementation of "mkdir -p".
ssize_t GNUNET_DISK_fn_read(const char *fn, void *result, size_t len)
Read the contents of a binary file into a buffer.
int GNUNET_DISK_directory_scan(const char *dir_name, GNUNET_FileNameCallback callback, void *callback_cls)
Scan a directory for files.
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_GROUP_READ
Group can read.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
@ GNUNET_DISK_PERM_OTHER_READ
Everybody can read.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
void * GNUNET_CONTAINER_multipeermap_get(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Given a key find a value in the map matching the key.
int GNUNET_CONTAINER_multipeermap_get_multiple(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map that match a particular key.
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
int GNUNET_HELLO_get_id(const struct GNUNET_HELLO_Message *hello, struct GNUNET_PeerIdentity *peer)
Get the peer identity from a HELLO message.
uint16_t GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello)
Return the size of the given HELLO message.
struct GNUNET_HELLO_Message * GNUNET_HELLO_create(const struct GNUNET_CRYPTO_EddsaPublicKey *public_key, GNUNET_HELLO_GenerateAddressListCallback addrgen, void *addrgen_cls, int friend_only)
Construct a HELLO message given the public key, expiration time and an iterator that spews the transp...
struct GNUNET_HELLO_Message * GNUNET_HELLO_merge(const struct GNUNET_HELLO_Message *h1, const struct GNUNET_HELLO_Message *h2)
Construct a HELLO message by merging the addresses in two existing HELLOs (which must be for the same...
int GNUNET_HELLO_is_friend_only(const struct GNUNET_HELLO_Message *h)
Return HELLO type.
struct GNUNET_TIME_Absolute GNUNET_HELLO_equals(const struct GNUNET_HELLO_Message *h1, const struct GNUNET_HELLO_Message *h2, struct GNUNET_TIME_Absolute now)
Test if two HELLO messages contain the same addresses.
struct GNUNET_HELLO_Message * GNUNET_HELLO_iterate_addresses(const struct GNUNET_HELLO_Message *msg, int return_modified, GNUNET_HELLO_AddressIterator it, void *it_cls)
Iterate over all of the addresses in the HELLO.
#define GNUNET_log(kind,...)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a string representing a public key to a public key.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_SCHEDULER_PRIORITY_IDLE
Run when otherwise idle.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_notification_context_destroy(struct GNUNET_NotificationContext *nc)
Destroy the context, force disconnect for all subscribers.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
void GNUNET_notification_context_broadcast(struct GNUNET_NotificationContext *nc, const struct GNUNET_MessageHeader *msg, int can_drop)
Send a message to all subscribers of this context.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
struct GNUNET_NotificationContext * GNUNET_notification_context_create(unsigned int queue_length)
Create a new notification context.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_notification_context_add(struct GNUNET_NotificationContext *nc, struct GNUNET_MQ_Handle *mq)
Add a subscriber to the notification context.
char * GNUNET_OS_installation_get_path(enum GNUNET_OS_InstallationPathKind dirkind)
Get the path to a specific GNUnet installation directory or, with GNUNET_OS_IPK_SELF_PREFIX,...
@ GNUNET_OS_IPK_DATADIR
Return the directory where data is installed (share/gnunet/)
#define GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END
End of information about other peers.
#define GNUNET_MESSAGE_TYPE_PEERINFO_GET
Request update and listing of a peer.
#define GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL
Request update and listing of all peers.
#define GNUNET_MESSAGE_TYPE_PEERINFO_INFO
Information about one of the peers.
#define GNUNET_MESSAGE_TYPE_HELLO
HELLO message with friend only flag used for communicating peer addresses.
#define GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY
Start notifying this client about all changes to the known peers until it disconnects.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed_with_priority(struct GNUNET_TIME_Relative delay, enum GNUNET_SCHEDULER_Priority priority, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_with_priority(enum GNUNET_SCHEDULER_Priority prio, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified priority.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
void GNUNET_SERVICE_client_mark_monitor(struct GNUNET_SERVICE_Client *c)
Set the 'monitor' flag on this client.
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
@ GNUNET_SERVICE_OPTION_NONE
Use defaults.
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
static unsigned int size
Size of the "table".
common internal definitions for peerinfo service
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
static struct GNUNET_TIME_Relative delta
Closure for hosts_directory_scan_callback().
int remove_files
GNUNET_YES if we should remove files that are broken, GNUNET_NO if the directory we are iterating ove...
unsigned int matched
Counter for the number of (valid) entries found, incremented by one for each match.
Internal representation of the hash map.
An address for communicating with a peer.
A HELLO message is used to exchange information about transports with other peers.
Handle to a message queue.
The notification context is the key datastructure for a convenience API used for transmission of noti...
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Entry in list of pending tasks.
Handle to a client that is connected to a service.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
In-memory cache of known hosts.
struct GNUNET_HELLO_Message * hello
Hello for the peer (can be NULL)
struct GNUNET_PeerIdentity identity
Identity of the peer.
struct GNUNET_HELLO_Message * friend_only_hello
Friend only hello for the peer (can be NULL)
Message used to inform the client about a particular peer; this message is optionally followed by a H...
struct GNUNET_PeerIdentity peer
About which peer are we talking here?
struct GNUNET_MessageHeader header
Type will be GNUNET_MESSAGE_TYPE_PEERINFO_INFO.
Message requesting a listing of all peers, restricted to the specified peer identity.
uint32_t include_friend_only
Include friend only HELLOs and peers in callbacks.
Message requesting a listing of peers, restricted to the specified peer identity.
struct GNUNET_PeerIdentity peer
Restrict to peers with this identity (optional field, check header.size!).
uint32_t include_friend_only
Include friend only HELLOs and peers in callbacks.
Header for all communications.
uint32_t include_friend_only
Include friend only HELLOs and peers in callbacks.
Result of reading a file.
struct GNUNET_HELLO_Message * friend_only_hello
Friend only hello for the peer (can be NULL)
struct GNUNET_HELLO_Message * hello
Hello for the peer (can be NULL)
struct GNUNET_SERVICE_Client * client
Client to transmit to.
int friend_only
Include friend only HELLOs GNUNET_YES or GNUNET_NO.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.