GNUnet  0.10.x
Data Structures | Macros | Enumerations | Functions | Variables
gnunet-service-transport_neighbours.c File Reference

neighbour management More...

#include "platform.h"
#include "gnunet_ats_service.h"
#include "gnunet-service-transport_ats.h"
#include "gnunet-service-transport_neighbours.h"
#include "gnunet-service-transport_manipulation.h"
#include "gnunet-service-transport_plugins.h"
#include "gnunet-service-transport_validation.h"
#include "gnunet-service-transport.h"
#include "gnunet_peerinfo_service.h"
#include "gnunet_constants.h"
#include "transport.h"
Include dependency graph for gnunet-service-transport_neighbours.c:

Go to the source code of this file.

Data Structures

struct  TransportSynMessage
 Message a peer sends to another to indicate that it intends to setup a connection/session for data exchange. More...
 
struct  GNUNET_ATS_SessionKeepAliveMessage
 Message a peer sends to another when connected to indicate that a session is in use and the peer is still alive or to respond to a keep alive. More...
 
struct  GNUNET_ATS_SessionQuotaMessage
 Message a peer sends to another when connected to indicate that the other peer should limit transmissions to the indicated quota. More...
 
struct  GNUNET_ATS_SessionDisconnectMessage
 Message we send to the other peer to notify it that we intentionally are disconnecting (to reduce timeouts). More...
 
struct  MessageQueue
 For each neighbour we keep a list of messages that we still want to transmit to the neighbour. More...
 
struct  NeighbourAddress
 A possible address we could use to communicate with a neighbour. More...
 
struct  NeighbourMapEntry
 Entry in neighbours. More...
 
struct  BlacklistCheckSwitchContext
 Entry in a DLL we use to keep track of pending blacklist checks. More...
 
struct  IteratorContext
 Closure for the neighbours_iterate() function. More...
 

Macros

#define IGNORE_INBOUND_QUOTA   GNUNET_YES
 Experimental option to ignore SessionQuotaMessages from the other peer. More...
 
#define NEIGHBOUR_TABLE_SIZE   256
 Size of the neighbour hash map. More...
 
#define DISCONNECT_SENT_TIMEOUT   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500)
 Time we give plugin to transmit DISCONNECT message before the neighbour entry self-destructs. More...
 
#define QUOTA_VIOLATION_DROP_THRESHOLD   10
 How often must a peer violate bandwidth quotas before we start to simply drop its messages? More...
 
#define ATS_RESPONSE_TIMEOUT   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5)
 How long are we willing to wait for a response from ATS before timing out? More...
 
#define SETUP_CONNECTION_TIMEOUT   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15)
 How long are we willing to wait for an ACK from the other peer before giving up on our connect operation? More...
 
#define FAST_RECONNECT_TIMEOUT   GNUNET_TIME_UNIT_SECONDS
 How long are we willing to wait for a successful reconnect if an existing connection went down? Much shorter than the usual SETUP_CONNECTION_TIMEOUT as we do not inform the higher layers about the disconnect during this period. More...
 
#define UTIL_TRANSMISSION_INTERVAL   GNUNET_TIME_UNIT_SECONDS
 Interval to send utilization data. More...
 

Enumerations

enum  GST_ACK_State { ACK_UNDEFINED = 0, ACK_SEND_SYN_ACK = 1, ACK_SEND_ACK = 2 }
 State describing which kind a reply this neighbour should send. More...
 

Functions

static char * print_ack_state (enum GST_ACK_State s)
 Convert the given ACK state to a string. More...
 
static void send_outbound_quota_to_clients (struct NeighbourMapEntry *n)
 Send information about a new outbound quota to our clients. More...
 
static void neighbours_connect_notification (struct NeighbourMapEntry *n)
 Notify our clients that another peer connected to us. More...
 
static void neighbours_disconnect_notification (struct NeighbourMapEntry *n)
 Notify our clients (and manipulation) that a peer disconnected from us. More...
 
static void neighbours_changed_notification (const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Address *address, enum GNUNET_TRANSPORT_PeerState state, struct GNUNET_TIME_Absolute state_timeout, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
 Notify transport clients that a neighbour peer changed its active address. More...
 
static struct NeighbourMapEntrylookup_neighbour (const struct GNUNET_PeerIdentity *pid)
 Lookup a neighbour entry in the neighbours hash map. More...
 
static int test_connected (struct NeighbourMapEntry *n)
 Test if we're connected to the given peer. More...
 
static void free_address (struct NeighbourAddress *na)
 We don't need a given neighbour address any more. More...
 
static void master_task (void *cls)
 Master task run for every neighbour. More...
 
static void set_state_and_timeout (struct NeighbourMapEntry *n, enum GNUNET_TRANSPORT_PeerState s, struct GNUNET_TIME_Absolute timeout)
 Set net state and state timeout for this neighbour and notify monitoring. More...
 
static void set_alternative_address (struct NeighbourMapEntry *n, const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
 Initialize the alternative address of a neighbour. More...
 
static struct GNUNET_TIME_Relative send_with_session (struct NeighbourMapEntry *n, const void *msgbuf, size_t msgbuf_size, uint32_t priority, struct GNUNET_TIME_Relative timeout, unsigned int use_keepalive_timeout, GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
 Transmit a message using the current session of the given neighbour. More...
 
static void unset_primary_address (struct NeighbourMapEntry *n)
 Clear the primary address of a neighbour since this address is not valid anymore and notify monitoring about it. More...
 
static void free_neighbour (struct NeighbourMapEntry *n)
 Free a neighbour map entry. More...
 
static void send_disconnect_cont (void *cls, const struct GNUNET_PeerIdentity *target, int result, size_t payload, size_t physical)
 Function called when the 'DISCONNECT' message has been sent by the plugin. More...
 
static void send_disconnect (struct NeighbourMapEntry *n)
 Transmit a DISCONNECT message to the other peer. More...
 
static void disconnect_neighbour (struct NeighbourMapEntry *n)
 Disconnect from the given neighbour, clean up the record. More...
 
static int set_incoming_quota (struct NeighbourMapEntry *n, struct GNUNET_BANDWIDTH_Value32NBO quota)
 Change the incoming quota for the given peer. More...
 
static void set_primary_address (struct NeighbourMapEntry *n, const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
 Initialize the primary address of a neighbour. More...
 
static void transmit_send_continuation (void *cls, const struct GNUNET_PeerIdentity *receiver, int success, size_t size_payload, size_t physical)
 We're done with our transmission attempt, continue processing. More...
 
static void try_transmission_to_peer (struct NeighbourMapEntry *n)
 Check the message list for the given neighbour and if we can send a message, do so. More...
 
static void send_keepalive (struct NeighbourMapEntry *n)
 Send keepalive message to the neighbour. More...
 
void GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour, const struct GNUNET_MessageHeader *m)
 Keep the connection to the given neighbour alive longer, we received a KEEPALIVE (or equivalent); send a response. More...
 
void GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour, const struct GNUNET_MessageHeader *m)
 We received a KEEP_ALIVE_RESPONSE message and use this to calculate latency to this peer. More...
 
struct GNUNET_TIME_Relative GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender, ssize_t size, int *do_forward)
 We have received a message from the given sender. More...
 
void GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg, size_t msg_size, struct GNUNET_TIME_Relative timeout, GST_NeighbourSendContinuation cont, void *cont_cls)
 Transmit a message to the given target using the active connection. More...
 
static void send_session_syn_cont (void *cls, const struct GNUNET_PeerIdentity *target, int result, size_t size_payload, size_t size_on_wire)
 Continuation called from our attempt to transmitted our GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN to the specified target. More...
 
static void send_syn (struct NeighbourAddress *na)
 Send a SYN message via the given address. More...
 
static void send_session_syn_ack_cont (void *cls, const struct GNUNET_PeerIdentity *target, int result, size_t size_payload, size_t size_on_wire)
 Continuation called from our attempt to transmitted our GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK to the specified target. More...
 
static void send_syn_ack_message (struct NeighbourAddress *na, struct GNUNET_TIME_Absolute timestamp)
 Send a SYN_ACK message via the given address. More...
 
static void inbound_bw_tracker_update (void *cls)
 Function called by the bandwidth tracker for a peer whenever the tracker's state changed such that we need to recalculate the delay for flow control. More...
 
static struct NeighbourMapEntrysetup_neighbour (const struct GNUNET_PeerIdentity *peer)
 Create a fresh entry in the neighbour map for the given peer. More...
 
int GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message, const struct GNUNET_PeerIdentity *peer)
 We received a 'SYN' message from the other peer. More...
 
static int try_run_fast_ats_update (const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
 Check if the given address is the same that we are already using for the respective neighbour. More...
 
static void switch_address_bl_check_cont (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session, int result)
 We've been asked to switch addresses, and just now got the result from the blacklist check to see if this is allowed. More...
 
void GST_neighbours_switch_to_address (const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
 For the given peer, switch to this address. More...
 
static int send_utilization_data (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Function called to send network utilization data to ATS for each active connection. More...
 
static void utilization_transmission (void *cls)
 Task transmitting utilization in a regular interval. More...
 
void GST_neighbours_notify_data_recv (const struct GNUNET_HELLO_Address *address, const struct GNUNET_MessageHeader *message)
 Track information about data we received from the given address (used to notify ATS about our utilization of allocated resources). More...
 
void GST_neighbours_notify_data_sent (const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session, size_t size)
 Track information about data we transmitted using the given address and session (used to notify ATS about our utilization of allocated resources). More...
 
static void send_session_ack_message (struct NeighbourMapEntry *n)
 Send a ACK message to the neighbour to confirm that we got its SYN_ACK. More...
 
int GST_neighbours_handle_session_syn_ack (const struct GNUNET_MessageHeader *message, const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session)
 We received a 'SESSION_SYN_ACK' message from the other peer. More...
 
int GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer, struct GNUNET_ATS_Session *session)
 A session was terminated. More...
 
int GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message, const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session)
 We received a 'ACK' message from the other peer. More...
 
int GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target)
 Test if we're connected to the given peer. More...
 
static void delayed_disconnect (void *cls)
 Task to asynchronously run free_neighbour(). More...
 
void GST_neighbours_handle_quota_message (const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *msg)
 We received a quota message from the given peer, validate and process. More...
 
void GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *msg)
 We received a disconnect message from the given peer, validate and process. More...
 
static int neighbours_iterate (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Call the callback from the closure for each neighbour. More...
 
void GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls)
 Iterate over all connected neighbours. More...
 
void GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target)
 If we have an active connection to the given target, it must be shutdown. More...
 
const struct GNUNET_HELLO_AddressGST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer)
 Obtain current address information for the given neighbour. More...
 
void GST_neighbours_start (unsigned int max_fds)
 Initialize the neighbours subsystem. More...
 
static int disconnect_all_neighbours (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Disconnect from the given neighbour. More...
 
void GST_neighbours_stop ()
 Cleanup the neighbours subsystem. More...
 

Variables

static struct GNUNET_CONTAINER_MultiPeerMapneighbours
 Hash map from peer identities to the respective struct NeighbourMapEntry. More...
 
static struct BlacklistCheckSwitchContextpending_bc_head
 List of pending blacklist checks: head. More...
 
static struct BlacklistCheckSwitchContextpending_bc_tail
 List of pending blacklist checks: tail. More...
 
static unsigned int neighbours_connected
 counter for connected neighbours More...
 
static unsigned long long bytes_in_send_queue
 Number of bytes we have currently queued for transmission. More...
 
static struct GNUNET_SCHEDULER_Taskutil_transmission_tk
 Task transmitting utilization data. More...
 

Detailed Description

neighbour management

Author
Christian Grothoff

Definition in file gnunet-service-transport_neighbours.c.

Macro Definition Documentation

◆ IGNORE_INBOUND_QUOTA

#define IGNORE_INBOUND_QUOTA   GNUNET_YES

Experimental option to ignore SessionQuotaMessages from the other peer.

Definition at line 42 of file gnunet-service-transport_neighbours.c.

◆ NEIGHBOUR_TABLE_SIZE

#define NEIGHBOUR_TABLE_SIZE   256

Size of the neighbour hash map.

Definition at line 47 of file gnunet-service-transport_neighbours.c.

Referenced by GST_neighbours_start().

◆ DISCONNECT_SENT_TIMEOUT

#define DISCONNECT_SENT_TIMEOUT   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500)

Time we give plugin to transmit DISCONNECT message before the neighbour entry self-destructs.

Definition at line 53 of file gnunet-service-transport_neighbours.c.

Referenced by disconnect_neighbour().

◆ QUOTA_VIOLATION_DROP_THRESHOLD

#define QUOTA_VIOLATION_DROP_THRESHOLD   10

How often must a peer violate bandwidth quotas before we start to simply drop its messages?

Definition at line 59 of file gnunet-service-transport_neighbours.c.

Referenced by GST_neighbours_calculate_receive_delay().

◆ ATS_RESPONSE_TIMEOUT

#define ATS_RESPONSE_TIMEOUT   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5)

How long are we willing to wait for a response from ATS before timing out?

Definition at line 64 of file gnunet-service-transport_neighbours.c.

Referenced by GST_neighbours_handle_session_syn(), GST_neighbours_session_terminated(), master_task(), send_session_syn_ack_cont(), send_session_syn_cont(), send_syn(), and send_syn_ack_message().

◆ SETUP_CONNECTION_TIMEOUT

#define SETUP_CONNECTION_TIMEOUT   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15)

How long are we willing to wait for an ACK from the other peer before giving up on our connect operation?

Definition at line 70 of file gnunet-service-transport_neighbours.c.

Referenced by master_task(), send_syn(), and switch_address_bl_check_cont().

◆ FAST_RECONNECT_TIMEOUT

#define FAST_RECONNECT_TIMEOUT   GNUNET_TIME_UNIT_SECONDS

How long are we willing to wait for a successful reconnect if an existing connection went down? Much shorter than the usual SETUP_CONNECTION_TIMEOUT as we do not inform the higher layers about the disconnect during this period.

Definition at line 78 of file gnunet-service-transport_neighbours.c.

Referenced by GST_neighbours_session_terminated(), send_session_syn_cont(), send_syn(), and switch_address_bl_check_cont().

◆ UTIL_TRANSMISSION_INTERVAL

#define UTIL_TRANSMISSION_INTERVAL   GNUNET_TIME_UNIT_SECONDS

Interval to send utilization data.

Definition at line 83 of file gnunet-service-transport_neighbours.c.

Referenced by GST_neighbours_start(), and utilization_transmission().

Enumeration Type Documentation

◆ GST_ACK_State

State describing which kind a reply this neighbour should send.

Enumerator
ACK_UNDEFINED 

We did not receive a SYN message for this neighbour.

ACK_SEND_SYN_ACK 

The neighbour received a SYN message and has to send a SYN_ACK as reply.

ACK_SEND_ACK 

The neighbour sent a SYN_ACK message and has to send a ACK as reply.

Definition at line 88 of file gnunet-service-transport_neighbours.c.

88  {
92  ACK_UNDEFINED = 0,
93 
98  ACK_SEND_SYN_ACK = 1,
99 
104  ACK_SEND_ACK = 2
105 };
We did not receive a SYN message for this neighbour.
The neighbour sent a SYN_ACK message and has to send a ACK as reply.
The neighbour received a SYN message and has to send a SYN_ACK as reply.

Function Documentation

◆ print_ack_state()

static char* print_ack_state ( enum GST_ACK_State  s)
static

Convert the given ACK state to a string.

Parameters
sstate
Returns
corresponding human-readable string

Definition at line 486 of file gnunet-service-transport_neighbours.c.

References ACK_SEND_ACK, ACK_SEND_SYN_ACK, ACK_UNDEFINED, and GNUNET_break.

Referenced by GST_neighbours_handle_session_ack(), GST_neighbours_handle_session_syn(), and GST_neighbours_handle_session_syn_ack().

487 {
488  switch (s)
489  {
490  case ACK_UNDEFINED:
491  return "UNDEFINED";
492 
493  case ACK_SEND_SYN_ACK:
494  return "SEND_SYN_ACK";
495 
496  case ACK_SEND_ACK:
497  return "SEND_ACK";
498 
499  default:
500  GNUNET_break(0);
501  return "N/A";
502  }
503 }
We did not receive a SYN message for this neighbour.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
The neighbour sent a SYN_ACK message and has to send a ACK as reply.
The neighbour received a SYN message and has to send a SYN_ACK as reply.
Here is the caller graph for this function:

◆ send_outbound_quota_to_clients()

static void send_outbound_quota_to_clients ( struct NeighbourMapEntry n)
static

Send information about a new outbound quota to our clients.

Note that the outbound quota is enforced client-side (i.e. in libgnunettransport).

Parameters
naffected peer

Definition at line 514 of file gnunet-service-transport_neighbours.c.

References NeighbourAddress::bandwidth_out, GNUNET_BANDWIDTH_value_min(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, GNUNET_NO, GNUNET_TRANSPORT_is_connected(), GST_clients_broadcast(), QuotaSetMessage::header, NeighbourMapEntry::id, NeighbourMapEntry::neighbour_receive_quota, QuotaSetMessage::peer, NeighbourMapEntry::primary_address, QuotaSetMessage::quota, GNUNET_MessageHeader::size, NeighbourMapEntry::state, GNUNET_MessageHeader::type, and GNUNET_BANDWIDTH_Value32NBO::value__.

Referenced by GST_neighbours_handle_quota_message(), set_primary_address(), and try_run_fast_ats_update().

515 {
516  struct QuotaSetMessage q_msg;
517  struct GNUNET_BANDWIDTH_Value32NBO bandwidth_min;
518 
520  return;
521 #if IGNORE_INBOUND_QUOTA
522  bandwidth_min = n->primary_address.bandwidth_out;
523 #else
526 #endif
527 
529  "Sending outbound quota of %u Bps for peer `%s' to all clients\n",
530  ntohl(bandwidth_min.value__),
531  GNUNET_i2s(&n->id));
532  q_msg.header.size = htons(sizeof(struct QuotaSetMessage));
533  q_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA);
534  q_msg.quota = bandwidth_min;
535  q_msg.peer = n->id;
536  GST_clients_broadcast(&q_msg.header,
537  GNUNET_NO);
538 }
void GST_clients_broadcast(const struct GNUNET_MessageHeader *msg, int may_drop)
Broadcast the given message to all of our clients.
struct GNUNET_BANDWIDTH_Value32NBO GNUNET_BANDWIDTH_value_min(struct GNUNET_BANDWIDTH_Value32NBO b1, struct GNUNET_BANDWIDTH_Value32NBO b2)
Compute the MIN of two bandwidth values.
Definition: bandwidth.c:56
#define GNUNET_NO
Definition: gnunet_common.h:78
int GNUNET_TRANSPORT_is_connected(enum GNUNET_TRANSPORT_PeerState state)
Check if a state is defined as connected.
struct NeighbourAddress primary_address
Primary address we currently use to communicate with the neighbour.
struct GNUNET_PeerIdentity id
Identity of this neighbour.
Message used to set a particular bandwidth quota.
Definition: transport.h:172
32-bit bandwidth used for network exchange by GNUnet, in bytes per second.
enum GNUNET_TRANSPORT_PeerState state
The current state of the peer.
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out
Outbound bandwidth from ATS for this address.
#define GNUNET_log(kind,...)
struct GNUNET_BANDWIDTH_Value32NBO neighbour_receive_quota
Latest quota the other peer send us in bytes per second.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA
Message telling transport to limit its receive rate.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ neighbours_connect_notification()

static void neighbours_connect_notification ( struct NeighbourMapEntry n)
static

Notify our clients that another peer connected to us.

Parameters
nthe peer that connected

Definition at line 547 of file gnunet-service-transport_neighbours.c.

References NeighbourAddress::bandwidth_out, buf, GNUNET_ALIGN, GNUNET_BANDWIDTH_value_min(), GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_log, GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT, GNUNET_NO, GST_clients_broadcast(), ConnectInfoMessage::header, ConnectInfoMessage::id, NeighbourMapEntry::id, len, NeighbourMapEntry::neighbour_receive_quota, NeighbourMapEntry::primary_address, ConnectInfoMessage::quota_out, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

Referenced by set_state_and_timeout().

548 {
549  size_t len = sizeof(struct ConnectInfoMessage);
550  char buf[len] GNUNET_ALIGN;
551  struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *)buf;
552  struct GNUNET_BANDWIDTH_Value32NBO bandwidth_min;
553 
554 #if IGNORE_INBOUND_QUOTA
555  bandwidth_min = n->primary_address.bandwidth_out;
556 #else
559 #endif
561  "We are now connected to peer `%s'\n",
562  GNUNET_i2s(&n->id));
563  connect_msg->header.size = htons(sizeof(buf));
564  connect_msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
565  connect_msg->id = n->id;
566  connect_msg->quota_out = bandwidth_min;
567  GST_clients_broadcast(&connect_msg->header,
568  GNUNET_NO);
569 }
struct GNUNET_PeerIdentity id
Identity of the new neighbour.
Definition: transport.h:139
void GST_clients_broadcast(const struct GNUNET_MessageHeader *msg, int may_drop)
Broadcast the given message to all of our clients.
struct GNUNET_BANDWIDTH_Value32NBO GNUNET_BANDWIDTH_value_min(struct GNUNET_BANDWIDTH_Value32NBO b1, struct GNUNET_BANDWIDTH_Value32NBO b2)
Compute the MIN of two bandwidth values.
Definition: bandwidth.c:56
struct GNUNET_MessageHeader header
Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT.
Definition: transport.h:120
struct GNUNET_BANDWIDTH_Value32NBO quota_out
Current outbound quota for this peer.
Definition: transport.h:133
#define GNUNET_NO
Definition: gnunet_common.h:78
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT
Message from TRANSPORT notifying about a client that connected to us.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
struct NeighbourAddress primary_address
Primary address we currently use to communicate with the neighbour.
static char buf[2048]
Message from the transport service to the library informing about neighbors.
Definition: transport.h:116
struct GNUNET_PeerIdentity id
Identity of this neighbour.
32-bit bandwidth used for network exchange by GNUnet, in bytes per second.
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out
Outbound bandwidth from ATS for this address.
#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_log(kind,...)
struct GNUNET_BANDWIDTH_Value32NBO neighbour_receive_quota
Latest quota the other peer send us in bytes per second.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ neighbours_disconnect_notification()

static void neighbours_disconnect_notification ( struct NeighbourMapEntry n)
static

Notify our clients (and manipulation) that a peer disconnected from us.

Parameters
nthe peer that disconnected

Definition at line 579 of file gnunet-service-transport_neighbours.c.

References GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_log, GST_clients_broadcast_disconnect(), GST_manipulation_peer_disconnect(), and NeighbourMapEntry::id.

Referenced by set_state_and_timeout().

580 {
582  "Peer `%s' disconnected\n",
583  GNUNET_i2s(&n->id));
586 }
void GST_manipulation_peer_disconnect(const struct GNUNET_PeerIdentity *peer)
Notify manipulation about disconnect so it can discard queued messages.
struct GNUNET_PeerIdentity id
Identity of this neighbour.
void GST_clients_broadcast_disconnect(const struct GNUNET_PeerIdentity *peer)
Notify all clients about a disconnect, and cancel pending SEND_OK messages for this peer...
#define GNUNET_log(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ neighbours_changed_notification()

static void neighbours_changed_notification ( const struct GNUNET_PeerIdentity peer,
const struct GNUNET_HELLO_Address address,
enum GNUNET_TRANSPORT_PeerState  state,
struct GNUNET_TIME_Absolute  state_timeout,
struct GNUNET_BANDWIDTH_Value32NBO  bandwidth_in,
struct GNUNET_BANDWIDTH_Value32NBO  bandwidth_out 
)
static

Notify transport clients that a neighbour peer changed its active address.

Parameters
peeridentity of the peer
addressaddress possibly NULL if peer is not connected
statecurrent state this peer is in
state_timeouttimeout for the current state of the peer
bandwidth_inbandwidth assigned inbound, 0 on disconnect
bandwidth_outbandwidth assigned outbound, 0 on disconnect

Definition at line 601 of file gnunet-service-transport_neighbours.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_STRINGS_absolute_time_to_string(), GNUNET_TRANSPORT_ps2s(), GST_clients_broadcast_peer_notification(), and GST_plugins_a2s().

Referenced by set_primary_address(), set_state_and_timeout(), and unset_primary_address().

607 {
608  (void)bandwidth_in;
609  (void)bandwidth_out;
611  "Notifying about change for peer `%s' with address `%s' in state `%s' timing out at %s\n",
612  GNUNET_i2s(peer),
613  GST_plugins_a2s(address),
616  /* FIXME: include bandwidth in notification! */
618  address,
619  state,
620  state_timeout);
621 }
void GST_clients_broadcast_peer_notification(const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Address *address, enum GNUNET_TRANSPORT_PeerState state, struct GNUNET_TIME_Absolute state_timeout)
Broadcast the new active address to all clients monitoring the peer.
enum State state
current state of profiling
const char * GST_plugins_a2s(const struct GNUNET_HELLO_Address *address)
Convert a given address to a human-readable format.
const char * GNUNET_TRANSPORT_ps2s(enum GNUNET_TRANSPORT_PeerState state)
Convert a transport state to a human readable string.
#define GNUNET_log(kind,...)
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:741
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lookup_neighbour()

static struct NeighbourMapEntry* lookup_neighbour ( const struct GNUNET_PeerIdentity pid)
static

Lookup a neighbour entry in the neighbours hash map.

Parameters
pididentity of the peer to look up
Returns
the entry, NULL if there is no existing record

Definition at line 631 of file gnunet-service-transport_neighbours.c.

References GNUNET_CONTAINER_multipeermap_get().

Referenced by GST_neighbour_get_current_address(), GST_neighbours_calculate_receive_delay(), GST_neighbours_force_disconnect(), GST_neighbours_handle_disconnect_message(), GST_neighbours_handle_quota_message(), GST_neighbours_handle_session_ack(), GST_neighbours_handle_session_syn(), GST_neighbours_handle_session_syn_ack(), GST_neighbours_keepalive(), GST_neighbours_keepalive_response(), GST_neighbours_notify_data_recv(), GST_neighbours_notify_data_sent(), GST_neighbours_send(), GST_neighbours_session_terminated(), GST_neighbours_test_connected(), send_disconnect_cont(), send_session_syn_ack_cont(), send_session_syn_cont(), send_syn(), send_syn_ack_message(), switch_address_bl_check_cont(), transmit_send_continuation(), and try_run_fast_ats_update().

632 {
633  if (NULL == neighbours)
634  return NULL;
636 }
static struct GNUNET_CONTAINER_MultiPeerMap * neighbours
Hash map from peer identities to the respective struct NeighbourMapEntry.
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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_connected()

static int test_connected ( struct NeighbourMapEntry n)
static

Test if we're connected to the given peer.

Parameters
nneighbour entry of peer to test
Returns
GNUNET_YES if we are connected, GNUNET_NO if not

Definition at line 646 of file gnunet-service-transport_neighbours.c.

References GNUNET_NO, GNUNET_TRANSPORT_is_connected(), and NeighbourMapEntry::state.

Referenced by GST_neighbours_calculate_receive_delay(), GST_neighbours_force_disconnect(), GST_neighbours_send(), GST_neighbours_test_connected(), send_utilization_data(), and set_incoming_quota().

647 {
648  if (NULL == n)
649  return GNUNET_NO;
651 }
#define GNUNET_NO
Definition: gnunet_common.h:78
int GNUNET_TRANSPORT_is_connected(enum GNUNET_TRANSPORT_PeerState state)
Check if a state is defined as connected.
enum GNUNET_TRANSPORT_PeerState state
The current state of the peer.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_address()

static void free_address ( struct NeighbourAddress na)
static

We don't need a given neighbour address any more.

Release its resources and give appropriate notifications to ATS and other subsystems.

Parameters
naaddress we are done with; na itself must NOT be 'free'd, only the contents!

Definition at line 662 of file gnunet-service-transport_neighbours.c.

References NeighbourAddress::address, NeighbourAddress::ats_active, NeighbourAddress::bandwidth_in, NeighbourAddress::bandwidth_out, GNUNET_BANDWIDTH_value_init(), GNUNET_HELLO_address_free, GNUNET_NO, GNUNET_YES, GST_ats_block_address(), GST_validation_set_address_use(), NeighbourAddress::keep_alive_nonce, master_task(), and NeighbourAddress::session.

Referenced by free_neighbour(), GST_neighbours_session_terminated(), master_task(), send_session_syn_cont(), send_syn(), set_alternative_address(), set_primary_address(), switch_address_bl_check_cont(), and unset_primary_address().

663 {
664  if (GNUNET_YES == na->ats_active)
666  GNUNET_NO);
667  if (NULL != na->address)
668  {
670  na->session);
672  na->address = NULL;
673  }
676  na->ats_active = GNUNET_NO;
677  na->keep_alive_nonce = 0;
678  na->session = NULL;
679 }
#define GNUNET_NO
Definition: gnunet_common.h:78
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in
Inbound bandwidth from ATS for this address.
void GST_validation_set_address_use(const struct GNUNET_HELLO_Address *address, int in_use)
Update if we are using an address for a connection actively right now.
struct GNUNET_ATS_Session * session
Active session for this address.
int ats_active
Did we tell ATS that this is our 'active' address?
struct GNUNET_HELLO_Address * address
Network-level address information.
struct GNUNET_BANDWIDTH_Value32NBO GNUNET_BANDWIDTH_value_init(uint32_t bytes_per_second)
Create a new bandwidth value.
Definition: bandwidth.c:39
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out
Outbound bandwidth from ATS for this address.
#define GNUNET_YES
Definition: gnunet_common.h:77
uint32_t keep_alive_nonce
The current nonce sent in the last keep alive messages.
void GST_ats_block_address(const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session)
Temporarily block a valid address for use by ATS for address suggestions.
#define GNUNET_HELLO_address_free(addr)
Free an address.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ master_task()

static void master_task ( void *  cls)
static

Master task run for every neighbour.

Performs all of the time-related activities (keep alive, send next message, disconnect if idle, finish clean up after disconnect).

Parameters
clsthe struct NeighbourMapEntry for which we are running

Performs all of the time-related activities (keep alive, send next message, disconnect if idle, finish clean up after disconnect).

Parameters
clsthe 'struct NeighbourMapEntry' for which we are running

Definition at line 2968 of file gnunet-service-transport_neighbours.c.

References NeighbourMapEntry::alternative_address, ATS_RESPONSE_TIMEOUT, disconnect_neighbour(), free_address(), free_neighbour(), GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_log, GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_relative_min(), GNUNET_TIME_relative_to_absolute(), GNUNET_TRANSPORT_ps2s(), GNUNET_TRANSPORT_PS_CONNECTED, GNUNET_TRANSPORT_PS_DISCONNECT, GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED, GNUNET_TRANSPORT_PS_INIT_ATS, GNUNET_TRANSPORT_PS_NOT_CONNECTED, GNUNET_TRANSPORT_PS_RECONNECT_ATS, GNUNET_TRANSPORT_PS_RECONNECT_SENT, GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT, GNUNET_TRANSPORT_PS_SYN_RECV_ACK, GNUNET_TRANSPORT_PS_SYN_RECV_ATS, GNUNET_TRANSPORT_PS_SYN_SENT, GNUNET_YES, NeighbourMapEntry::id, NeighbourMapEntry::keep_alive_time, GNUNET_TIME_Relative::rel_value_us, send_keepalive(), set_state_and_timeout(), SETUP_CONNECTION_TIMEOUT, NeighbourMapEntry::state, NeighbourMapEntry::task, NeighbourMapEntry::timeout, try_transmission_to_peer(), and unset_primary_address().

Referenced by disconnect_neighbour(), free_address(), GST_neighbours_send(), GST_neighbours_session_terminated(), send_disconnect_cont(), set_state_and_timeout(), setup_neighbour(), and transmit_send_continuation().

2969 {
2970  struct NeighbourMapEntry *n = cls;
2971  struct GNUNET_TIME_Relative delay;
2972 
2973  n->task = NULL;
2976  "Master task runs for neighbour `%s' in state %s with timeout in %s\n",
2977  GNUNET_i2s(&n->id),
2980  GNUNET_YES));
2981  switch (n->state)
2982  {
2984  /* invalid state for master task, clean up */
2985  GNUNET_break(0);
2986  free_neighbour(n);
2987  return;
2988 
2990  if (0 == delay.rel_value_us)
2991  {
2993  "Connection to `%s' timed out waiting for ATS to provide address\n",
2994  GNUNET_i2s(&n->id));
2995  free_neighbour(n);
2996  return;
2997  }
2998  break;
2999 
3001  if (0 == delay.rel_value_us)
3002  {
3004  "Connection to `%s' timed out waiting for other peer to send SYN_ACK\n",
3005  GNUNET_i2s(&n->id));
3006  /* Remove address and request and additional one */
3011  return;
3012  }
3013  break;
3014 
3016  if (0 == delay.rel_value_us)
3017  {
3019  "Connection to `%s' timed out waiting ATS to provide address to use for SYN_ACK\n",
3020  GNUNET_i2s(&n->id));
3021  free_neighbour(n);
3022  return;
3023  }
3024  break;
3025 
3027  if (0 == delay.rel_value_us)
3028  {
3030  "Connection to `%s' timed out waiting for other peer to send ACK\n",
3031  GNUNET_i2s(&n->id));
3033  return;
3034  }
3035  break;
3036 
3038  if (0 == delay.rel_value_us)
3039  {
3041  "Connection to `%s' timed out, missing KEEPALIVE_RESPONSEs\n",
3042  GNUNET_i2s(&n->id));
3044  return;
3045  }
3047  send_keepalive(n);
3048  break;
3049 
3051  if (0 == delay.rel_value_us)
3052  {
3054  "Connection to `%s' timed out, waiting for ATS replacement address\n",
3055  GNUNET_i2s(&n->id));
3057  return;
3058  }
3059  break;
3060 
3062  if (0 == delay.rel_value_us)
3063  {
3065  "Connection to `%s' timed out, waiting for other peer to SYN_ACK replacement address\n",
3066  GNUNET_i2s(&n->id));
3068  return;
3069  }
3070  break;
3071 
3073  if (0 == delay.rel_value_us)
3074  {
3076  "Switch failed, cleaning up alternative address\n");
3081  }
3083  send_keepalive(n);
3084  break;
3085 
3088  "Cleaning up connection to `%s' after sending DISCONNECT\n",
3089  GNUNET_i2s(&n->id));
3090  free_neighbour(n);
3091  return;
3092 
3094  /* how did we get here!? */
3095  GNUNET_assert(0);
3096  break;
3097 
3098  default:
3100  "Unhandled state `%s'\n",
3102  GNUNET_break(0);
3103  break;
3104  }
3108  {
3109  /* if we are *now* in one of the two states, we're sending
3110  keep alive messages, so we need to consider the keepalive
3111  delay, not just the connection timeout */
3113  delay);
3114  }
3115  if (NULL == n->task)
3117  &master_task,
3118  n);
3119 }
Connection got into trouble, rest of the system still believes it to be up, but we're getting a new a...
We have some primary connection, but ATS suggested we switch to some alternative; we now sent a SYN m...
uint64_t rel_value_us
The actual value.
Sent SYN over new address (either by ATS telling us to switch addresses or from RECONNECT_ATS); if th...
struct NeighbourAddress alternative_address
Alternative address currently under consideration for communicating with the neighbour.
We're finished with the disconnect; and are cleaning up the state now! We put the struct into this st...
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:246
struct GNUNET_TIME_Absolute timeout
Time where we should cut the connection (timeout) if we don't make progress in the state machine (or ...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Received a SYN, asking ATS about address suggestions.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static void free_neighbour(struct NeighbourMapEntry *n)
Free a neighbour map entry.
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.
Definition: scheduler.c:1237
Fresh peer or completely disconnected.
struct GNUNET_TIME_Absolute keep_alive_time
At what time should we sent the next keep-alive message?
#define SETUP_CONNECTION_TIMEOUT
How long are we willing to wait for an ACK from the other peer before giving up on our connect operat...
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:686
struct GNUNET_PeerIdentity id
Identity of this neighbour.
Asked to initiate connection, trying to get address from ATS.
struct GNUNET_SCHEDULER_Task * task
Main task that drives this peer (timeouts, keepalives, etc.).
struct GNUNET_TIME_Relative GNUNET_TIME_relative_min(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the minimum of two relative time values.
Definition: time.c:272
const char * GNUNET_TRANSPORT_ps2s(enum GNUNET_TRANSPORT_PeerState state)
Convert a transport state to a human readable string.
Sent SYN message to other peer, waiting for SYN_ACK.
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
enum GNUNET_TRANSPORT_PeerState state
The current state of the peer.
static void set_state_and_timeout(struct NeighbourMapEntry *n, enum GNUNET_TRANSPORT_PeerState s, struct GNUNET_TIME_Absolute timeout)
Set net state and state timeout for this neighbour and notify monitoring.
static void send_keepalive(struct NeighbourMapEntry *n)
Send keepalive message to the neighbour.
static void free_address(struct NeighbourAddress *na)
We don't need a given neighbour address any more.
static void unset_primary_address(struct NeighbourMapEntry *n)
Clear the primary address of a neighbour since this address is not valid anymore and notify monitorin...
Disconnect in progress (we're sending the DISCONNECT message to the other peer; after that is finishe...
static void disconnect_neighbour(struct NeighbourMapEntry *n)
Disconnect from the given neighbour, clean up the record.
#define ATS_RESPONSE_TIMEOUT
How long are we willing to wait for a response from ATS before timing out?
#define GNUNET_log(kind,...)
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
#define GNUNET_YES
Definition: gnunet_common.h:77
Got our SYN_ACK/ACK, connection is up.
static void master_task(void *cls)
Master task run for every neighbour.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
SYN request from other peer was SYN_ACK'ed, waiting for ACK.
static void try_transmission_to_peer(struct NeighbourMapEntry *n)
Check the message list for the given neighbour and if we can send a message, do so.
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_state_and_timeout()

static void set_state_and_timeout ( struct NeighbourMapEntry n,
enum GNUNET_TRANSPORT_PeerState  s,
struct GNUNET_TIME_Absolute  timeout 
)
static

Set net state and state timeout for this neighbour and notify monitoring.

Parameters
nthe respective neighbour
sthe new state
timeoutthe new timeout

Definition at line 701 of file gnunet-service-transport_neighbours.c.

References GNUNET_TIME_Absolute::abs_value_us, NeighbourAddress::address, NeighbourAddress::bandwidth_in, NeighbourAddress::bandwidth_out, gettext_noop, GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_add_at(), GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_set(), GNUNET_STRINGS_absolute_time_to_string(), GNUNET_TRANSPORT_is_connected(), GNUNET_TRANSPORT_ps2s(), GST_stats, NeighbourMapEntry::id, master_task(), neighbours_changed_notification(), neighbours_connect_notification(), neighbours_connected, neighbours_disconnect_notification(), NeighbourMapEntry::primary_address, NeighbourMapEntry::state, NeighbourMapEntry::task, timeout, and NeighbourMapEntry::timeout.

Referenced by disconnect_neighbour(), free_neighbour(), GST_neighbours_handle_session_ack(), GST_neighbours_handle_session_syn(), GST_neighbours_handle_session_syn_ack(), GST_neighbours_keepalive_response(), GST_neighbours_session_terminated(), master_task(), send_session_syn_ack_cont(), send_session_syn_cont(), send_syn(), send_syn_ack_message(), setup_neighbour(), and switch_address_bl_check_cont().

704 {
707  {
710  gettext_noop("# peers connected"),
712  GNUNET_NO);
713  }
714  if ((!GNUNET_TRANSPORT_is_connected(s)) &&
716  {
718  gettext_noop("# peers connected"),
720  GNUNET_NO);
722  }
723  n->state = s;
724  if ((timeout.abs_value_us < n->timeout.abs_value_us) &&
725  (NULL != n->task))
726  {
727  /* new timeout is earlier, reschedule master task */
729  n->task = GNUNET_SCHEDULER_add_at(timeout,
730  &master_task,
731  n);
732  }
733  n->timeout = timeout;
735  "Neighbour `%s' changed state to %s with timeout %s\n",
736  GNUNET_i2s(&n->id),
741  n->state,
742  n->timeout,
745 }
static void neighbours_changed_notification(const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Address *address, enum GNUNET_TRANSPORT_PeerState state, struct GNUNET_TIME_Absolute state_timeout, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
Notify transport clients that a neighbour peer changed its active address.
struct GNUNET_TIME_Absolute timeout
Time where we should cut the connection (timeout) if we don&#39;t make progress in the state machine (or ...
static void neighbours_connect_notification(struct NeighbourMapEntry *n)
Notify our clients that another peer connected to us.
#define GNUNET_NO
Definition: gnunet_common.h:78
uint64_t abs_value_us
The actual value.
int GNUNET_TRANSPORT_is_connected(enum GNUNET_TRANSPORT_PeerState state)
Check if a state is defined as connected.
static unsigned int neighbours_connected
counter for connected neighbours
static struct GNUNET_STATISTICS_Handle * GST_stats
Statistics handle.
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:114
struct NeighbourAddress primary_address
Primary address we currently use to communicate with the neighbour.
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in
Inbound bandwidth from ATS for this address.
struct GNUNET_PeerIdentity id
Identity of this neighbour.
static void neighbours_disconnect_notification(struct NeighbourMapEntry *n)
Notify our clients (and manipulation) that a peer disconnected from us.
struct GNUNET_SCHEDULER_Task * task
Main task that drives this peer (timeouts, keepalives, etc.).
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
const char * GNUNET_TRANSPORT_ps2s(enum GNUNET_TRANSPORT_PeerState state)
Convert a transport state to a human readable string.
struct GNUNET_HELLO_Address * address
Network-level address information.
enum GNUNET_TRANSPORT_PeerState state
The current state of the peer.
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out
Outbound bandwidth from ATS for this address.
#define GNUNET_log(kind,...)
static void master_task(void *cls)
Master task run for every neighbour.
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:741
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_at(struct GNUNET_TIME_Absolute at, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run at the specified time.
Definition: scheduler.c:1214
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define gettext_noop(String)
Definition: gettext.h:69
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_alternative_address()

static void set_alternative_address ( struct NeighbourMapEntry n,
const struct GNUNET_HELLO_Address address,
struct GNUNET_ATS_Session session,
struct GNUNET_BANDWIDTH_Value32NBO  bandwidth_in,
struct GNUNET_BANDWIDTH_Value32NBO  bandwidth_out 
)
static

Initialize the alternative address of a neighbour.

Parameters
nthe neighbour
addressaddress of the other peer, NULL if other peer connected to us
sessionsession to use (or NULL, in which case an address must be setup)
bandwidth_ininbound quota to be used when connection is up
bandwidth_outoutbound quota to be used when connection is up

Definition at line 760 of file gnunet-service-transport_neighbours.c.

References NeighbourAddress::address, NeighbourMapEntry::alternative_address, NeighbourAddress::ats_active, NeighbourAddress::bandwidth_in, NeighbourAddress::bandwidth_out, GNUNET_TRANSPORT_PluginFunctions::cls, free_address(), GNUNET_TRANSPORT_PluginFunctions::get_session, gettext_noop, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_HELLO_address_copy(), GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_YES, GST_ats_is_known(), GST_ats_new_session(), GST_plugins_a2s(), GST_plugins_find(), GST_stats, NeighbourMapEntry::id, NeighbourAddress::keep_alive_nonce, GNUNET_HELLO_Address::peer, NeighbourAddress::session, and GNUNET_HELLO_Address::transport_name.

Referenced by switch_address_bl_check_cont().

765 {
767 
768  if (NULL == (papi = GST_plugins_find(address->transport_name)))
769  {
770  GNUNET_break(0);
771  return;
772  }
773  if (session == n->alternative_address.session)
774  {
775  n->alternative_address.bandwidth_in = bandwidth_in;
776  n->alternative_address.bandwidth_out = bandwidth_out;
777  return;
778  }
779  if (NULL != n->alternative_address.address)
780  {
782  "Replacing existing alternative address with another one\n");
784  }
785  if (NULL == session)
786  session = papi->get_session(papi->cls,
787  address);
788  if (NULL == session)
789  {
791  "Failed to obtain new session for peer `%s' and address '%s'\n",
792  GNUNET_i2s(&address->peer),
793  GST_plugins_a2s(address));
795  gettext_noop("# session creation failed"),
796  1,
797  GNUNET_NO);
798  return;
799  }
800  GST_ats_new_session(address,
801  session);
803  "Neighbour `%s' configured alternative address %s\n",
804  GNUNET_i2s(&n->id),
805  GST_plugins_a2s(address));
806 
808  n->alternative_address.bandwidth_in = bandwidth_in;
809  n->alternative_address.bandwidth_out = bandwidth_out;
810  n->alternative_address.session = session;
816 }
GNUNET_TRANSPORT_CreateSession get_session
Function that will be called tell the plugin to create a session object.
int GST_ats_is_known(const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session)
Test if ATS knows about this address and session.
struct NeighbourAddress alternative_address
Alternative address currently under consideration for communicating with the neighbour.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_STATISTICS_Handle * GST_stats
Statistics handle.
void * cls
Closure for all of the callbacks.
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in
Inbound bandwidth from ATS for this address.
const char * transport_name
Name of the transport plugin enabling the communication using this address.
struct GNUNET_PeerIdentity id
Identity of this neighbour.
struct GNUNET_ATS_Session * session
Active session for this address.
const char * GST_plugins_a2s(const struct GNUNET_HELLO_Address *address)
Convert a given address to a human-readable format.
struct GNUNET_TRANSPORT_PluginFunctions * GST_plugins_find(const char *name)
Obtain the plugin API based on a plugin name.
int ats_active
Did we tell ATS that this is our &#39;active&#39; address?
struct GNUNET_HELLO_Address * address
Network-level address information.
struct GNUNET_PeerIdentity peer
For which peer is this an address?
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out
Outbound bandwidth from ATS for this address.
static void free_address(struct NeighbourAddress *na)
We don&#39;t need a given neighbour address any more.
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_copy(const struct GNUNET_HELLO_Address *address)
Copy an address struct.
Definition: address.c:109
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
uint32_t keep_alive_nonce
The current nonce sent in the last keep alive messages.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
void GST_ats_new_session(const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session)
Notify ATS about a new session now existing for the given address.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_with_session()

static struct GNUNET_TIME_Relative send_with_session ( struct NeighbourMapEntry n,
const void *  msgbuf,
size_t  msgbuf_size,
uint32_t  priority,
struct GNUNET_TIME_Relative  timeout,
unsigned int  use_keepalive_timeout,
GNUNET_TRANSPORT_TransmitContinuation  cont,
void *  cont_cls 
)
static

Transmit a message using the current session of the given neighbour.

Parameters
nentry for the recipient
msgbufbuffer to transmit
msgbuf_sizenumber of bytes in msgbuf buffer
prioritytransmission priority
timeouttransmission timeout
use_keepalive_timeoutGNUNET_YES to use plugin-specific keep-alive timeout (timeout is ignored in that case), GNUNET_NO otherwise
contcontinuation to call when finished (can be NULL)
cont_clsclosure for cont
Returns
timeout (copy of timeout or a calculated one if use_keepalive_timeout is GNUNET_YES.

Definition at line 836 of file gnunet-service-transport_neighbours.c.

References GNUNET_TRANSPORT_PluginFunctions::cls, GNUNET_assert, GNUNET_break, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_NO, GNUNET_SYSERR, GNUNET_TIME_relative_divide(), GNUNET_TIME_UNIT_FOREVER_REL, GST_neighbours_notify_data_sent(), GST_plugins_find(), GNUNET_TRANSPORT_PluginFunctions::query_keepalive_factor, result, and GNUNET_TRANSPORT_PluginFunctions::send.

Referenced by GST_neighbours_keepalive(), send_disconnect(), send_keepalive(), send_session_ack_message(), set_incoming_quota(), and try_transmission_to_peer().

844 {
847 
849  if (((NULL == (papi = GST_plugins_find(n->primary_address.address->transport_name)) ||
850  (-1 == papi->send(papi->cls,
852  msgbuf,
853  msgbuf_size,
854  priority,
855  (result = (GNUNET_NO == use_keepalive_timeout) ? timeout :
857  papi->query_keepalive_factor(papi->cls))),
858  cont,
859  cont_cls)))) &&
860  (NULL != cont))
861  cont(cont_cls,
862  &n->id,
864  msgbuf_size,
865  0);
868  msgbuf_size);
869  GNUNET_break(NULL != papi);
870  return result;
871 }
GNUNET_TRANSPORT_TransmitFunction send
Function that the transport service will use to transmit data to another peer.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
void * cls
Closure for all of the callbacks.
struct NeighbourAddress primary_address
Primary address we currently use to communicate with the neighbour.
void GST_neighbours_notify_data_sent(const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session, size_t size)
Track information about data we transmitted using the given address and session (used to notify ATS a...
const char * transport_name
Name of the transport plugin enabling the communication using this address.
static int result
Global testing status.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_PeerIdentity id
Identity of this neighbour.
struct GNUNET_ATS_Session * session
Active session for this address.
struct GNUNET_TRANSPORT_PluginFunctions * GST_plugins_find(const char *name)
Obtain the plugin API based on a plugin name.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_HELLO_Address * address
Network-level address information.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don&#39;t receive messages from the peer...
GNUNET_TRANSPORT_QueryKeepaliveFactorFunction query_keepalive_factor
Function that is used to query keepalive factor.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Divide relative time by a given factor.
Definition: time.c:525
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ unset_primary_address()

static void unset_primary_address ( struct NeighbourMapEntry n)
static

Clear the primary address of a neighbour since this address is not valid anymore and notify monitoring about it.

Parameters
nthe neighbour

Definition at line 881 of file gnunet-service-transport_neighbours.c.

References NeighbourAddress::address, free_address(), GNUNET_BANDWIDTH_value_init(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, NeighbourMapEntry::id, neighbours_changed_notification(), NeighbourMapEntry::primary_address, NeighbourMapEntry::state, and NeighbourMapEntry::timeout.

Referenced by free_neighbour(), GST_neighbours_session_terminated(), master_task(), send_session_syn_ack_cont(), send_session_syn_cont(), send_syn(), and send_syn_ack_message().

882 {
883  /* Notify monitoring about change */
884  if (NULL == n->primary_address.address)
885  return;
887  "Disabling primary address\n");
890  n->state,
891  n->timeout,
895 }
static void neighbours_changed_notification(const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Address *address, enum GNUNET_TRANSPORT_PeerState state, struct GNUNET_TIME_Absolute state_timeout, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
Notify transport clients that a neighbour peer changed its active address.
struct GNUNET_TIME_Absolute timeout
Time where we should cut the connection (timeout) if we don&#39;t make progress in the state machine (or ...
struct NeighbourAddress primary_address
Primary address we currently use to communicate with the neighbour.
struct GNUNET_PeerIdentity id
Identity of this neighbour.
struct GNUNET_HELLO_Address * address
Network-level address information.
struct GNUNET_BANDWIDTH_Value32NBO GNUNET_BANDWIDTH_value_init(uint32_t bytes_per_second)
Create a new bandwidth value.
Definition: bandwidth.c:39
enum GNUNET_TRANSPORT_PeerState state
The current state of the peer.
static void free_address(struct NeighbourAddress *na)
We don&#39;t need a given neighbour address any more.
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_neighbour()

static void free_neighbour ( struct NeighbourMapEntry n)
static

Free a neighbour map entry.

Parameters
nentry to free

Definition at line 904 of file gnunet-service-transport_neighbours.c.

References NeighbourAddress::address, NeighbourMapEntry::alternative_address, MessageQueue::cont, MessageQueue::cont_cls, NeighbourMapEntry::delayed_disconnect_task, free_address(), GNUNET_assert, GNUNET_ATS_connectivity_suggest_cancel(), GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multipeermap_remove(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_SCHEDULER_cancel(), GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED, GNUNET_YES, NeighbourMapEntry::id, NeighbourMapEntry::is_active, MessageQueue::message_buf_size, NeighbourMapEntry::messages_head, NeighbourMapEntry::messages_tail, mq, set_state_and_timeout(), NeighbourMapEntry::suggest_handle, NeighbourMapEntry::task, and unset_primary_address().

Referenced by delayed_disconnect(), disconnect_all_neighbours(), disconnect_neighbour(), GST_neighbours_handle_session_syn(), GST_neighbours_handle_session_syn_ack(), GST_neighbours_session_terminated(), master_task(), and switch_address_bl_check_cont().

905 {
906  struct MessageQueue *mq;
907 
909  "Freeing neighbour state of peer `%s'\n",
910  GNUNET_i2s(&n->id));
911  n->is_active = NULL; /* always free'd by its own continuation! */
912 
913  /* fail messages currently in the queue */
914  while (NULL != (mq = n->messages_head))
915  {
917  n->messages_tail,
918  mq);
919  if (NULL != mq->cont)
920  mq->cont(mq->cont_cls,
922  mq->message_buf_size,
923  0);
924  GNUNET_free(mq);
925  }
926  /* Mark peer as disconnected */
930  /* free addresses and mark as unused */
932 
933  if (NULL != n->alternative_address.address)
934  {
936  "Cleaning up alternative address\n");
938  }
941  &n->id,
942  n));
943 
944  /* Cancel address requests for this peer */
945  if (NULL != n->suggest_handle)
946  {
948  n->suggest_handle = NULL;
949  }
950 
951  /* Cancel the disconnect task */
952  if (NULL != n->delayed_disconnect_task)
953  {
955  n->delayed_disconnect_task = NULL;
956  }
957 
958  /* Cancel the master task */
959  if (NULL != n->task)
960  {
962  n->task = NULL;
963  }
964  /* free rest of memory */
965  GNUNET_free(n);
966 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static struct GNUNET_CONTAINER_MultiPeerMap * neighbours
Hash map from peer identities to the respective struct NeighbourMapEntry.
struct NeighbourAddress alternative_address
Alternative address currently under consideration for communicating with the neighbour.
We&#39;re finished with the disconnect; and are cleaning up the state now! We put the struct into this st...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
void GNUNET_ATS_connectivity_suggest_cancel(struct GNUNET_ATS_ConnectivitySuggestHandle *sh)
We no longer care about being connected to a peer.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
struct MessageQueue * messages_tail
Tail of list of messages we would like to send to this peer; must contain at most one message per cli...
struct GNUNET_ATS_ConnectivitySuggestHandle * suggest_handle
ATS address suggest handle.
void * cont_cls
Closure for cont.
For each neighbour we keep a list of messages that we still want to transmit to the neighbour...
struct GNUNET_PeerIdentity id
Identity of this neighbour.
struct MessageQueue * messages_head
Head of list of messages we would like to send to this peer; must contain at most one message per cli...
struct GNUNET_SCHEDULER_Task * task
Main task that drives this peer (timeouts, keepalives, etc.).
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_HELLO_Address * address
Network-level address information.
static void set_state_and_timeout(struct NeighbourMapEntry *n, enum GNUNET_TRANSPORT_PeerState s, struct GNUNET_TIME_Absolute timeout)
Set net state and state timeout for this neighbour and notify monitoring.
GST_NeighbourSendContinuation cont
Function to call once we&#39;re done.
static void free_address(struct NeighbourAddress *na)
We don&#39;t need a given neighbour address any more.
struct MessageQueue * is_active
Are we currently trying to send a message? If so, which one?
struct GNUNET_SCHEDULER_Task * delayed_disconnect_task
Task to disconnect neighbour after we received a DISCONNECT message.
static void unset_primary_address(struct NeighbourMapEntry *n)
Clear the primary address of a neighbour since this address is not valid anymore and notify monitorin...
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
size_t message_buf_size
Size of the message buf.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_disconnect_cont()

static void send_disconnect_cont ( void *  cls,
const struct GNUNET_PeerIdentity target,
int  result,
size_t  payload,
size_t  physical 
)
static

Function called when the 'DISCONNECT' message has been sent by the plugin.

Frees the neighbour — if the entry still exists.

Parameters
clsNULL
targetidentity of the neighbour that was disconnected
resultGNUNET_OK if the disconnect got out successfully
payloadbytes payload
physicalbytes on wire

Definition at line 980 of file gnunet-service-transport_neighbours.c.

References GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_TRANSPORT_PS_DISCONNECT, lookup_neighbour(), master_task(), NeighbourMapEntry::state, and NeighbourMapEntry::task.

Referenced by send_disconnect().

985 {
986  struct NeighbourMapEntry *n;
987 
988  (void)cls;
989  (void)result;
990  (void)payload;
991  (void)physical;
992  n = lookup_neighbour(target);
993  if (NULL == n)
994  return; /* already gone */
996  return; /* have created a fresh entry since */
997  if (NULL != n->task)
1000 }
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1264
static int result
Global testing status.
struct GNUNET_SCHEDULER_Task * task
Main task that drives this peer (timeouts, keepalives, etc.).
static struct NeighbourMapEntry * lookup_neighbour(const struct GNUNET_PeerIdentity *pid)
Lookup a neighbour entry in the neighbours hash map.
static unsigned long long payload
How much data are we currently storing in the database?
enum GNUNET_TRANSPORT_PeerState state
The current state of the peer.
Disconnect in progress (we&#39;re sending the DISCONNECT message to the other peer; after that is finishe...
static void master_task(void *cls)
Master task run for every neighbour.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_disconnect()

static void send_disconnect ( struct NeighbourMapEntry n)
static

Transmit a DISCONNECT message to the other peer.

Parameters
nneighbour to send DISCONNECT message.

Definition at line 1009 of file gnunet-service-transport_neighbours.c.

References gettext_noop, GNUNET_assert, GNUNET_CRYPTO_eddsa_sign(), GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_log, GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_hton(), GNUNET_TIME_UNIT_FOREVER_REL, GST_my_identity, GST_my_private_key, GST_stats, GNUNET_ATS_SessionDisconnectMessage::header, NeighbourMapEntry::id, GNUNET_ATS_SessionDisconnectMessage::public_key, GNUNET_PeerIdentity::public_key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, GNUNET_ATS_SessionDisconnectMessage::purpose, GNUNET_ATS_SessionDisconnectMessage::reserved, send_disconnect_cont(), send_with_session(), GNUNET_ATS_SessionDisconnectMessage::signature, GNUNET_CRYPTO_EccSignaturePurpose::size, GNUNET_MessageHeader::size, GNUNET_ATS_SessionDisconnectMessage::timestamp, and GNUNET_MessageHeader::type.

Referenced by disconnect_neighbour().

1010 {
1011  struct GNUNET_ATS_SessionDisconnectMessage disconnect_msg;
1012 
1014  "Sending DISCONNECT message to peer `%4s'\n",
1015  GNUNET_i2s(&n->id));
1016  disconnect_msg.header.size = htons(sizeof(struct GNUNET_ATS_SessionDisconnectMessage));
1017  disconnect_msg.header.type =
1019  disconnect_msg.reserved = htonl(0);
1020  disconnect_msg.purpose.size =
1021  htonl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) +
1022  sizeof(struct GNUNET_CRYPTO_EddsaPublicKey) +
1023  sizeof(struct GNUNET_TIME_AbsoluteNBO));
1024  disconnect_msg.purpose.purpose =
1026  disconnect_msg.timestamp =
1028  disconnect_msg.public_key = GST_my_identity.public_key;
1031  &disconnect_msg.purpose,
1032  &disconnect_msg.signature));
1033 
1034  (void)send_with_session(n,
1035  &disconnect_msg,
1036  sizeof(disconnect_msg),
1037  UINT32_MAX,
1039  GNUNET_NO,
1041  NULL);
1043  gettext_noop("# DISCONNECT messages sent"),
1044  1,
1045  GNUNET_NO);
1046 }
static struct GNUNET_PeerIdentity GST_my_identity
Our public key.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void send_disconnect_cont(void *cls, const struct GNUNET_PeerIdentity *target, int result, size_t payload, size_t physical)
Function called when the &#39;DISCONNECT&#39; message has been sent by the plugin.
int GNUNET_CRYPTO_eddsa_sign(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
EdDSA sign a given block.
Definition: crypto_ecc.c:989
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
Time for absolute time used by GNUnet, in microseconds and in network byte order. ...
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
static struct GNUNET_STATISTICS_Handle * GST_stats
Statistics handle.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_PeerIdentity id
Identity of this neighbour.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
Message we send to the other peer to notify it that we intentionally are disconnecting (to reduce tim...
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT
Transport DISCONNECT message exchanged between transport services to indicate that a connection shoul...
static struct GNUNET_CRYPTO_EddsaPrivateKey * GST_my_private_key
Our private key.
#define GNUNET_log(kind,...)
static struct GNUNET_TIME_Relative send_with_session(struct NeighbourMapEntry *n, const void *msgbuf, size_t msgbuf_size, uint32_t priority, struct GNUNET_TIME_Relative timeout, unsigned int use_keepalive_timeout, GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
Transmit a message using the current session of the given neighbour.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:655
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
#define gettext_noop(String)
Definition: gettext.h:69
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ disconnect_neighbour()

static void disconnect_neighbour ( struct NeighbourMapEntry n)
static

Disconnect from the given neighbour, clean up the record.

Parameters
nneighbour to disconnect from

Definition at line 1055 of file gnunet-service-transport_neighbours.c.

References DISCONNECT_SENT_TIMEOUT, free_neighbour(), GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_log, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TRANSPORT_ps2s(), GNUNET_TRANSPORT_PS_CONNECTED, GNUNET_TRANSPORT_PS_DISCONNECT, GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED, GNUNET_TRANSPORT_PS_INIT_ATS, GNUNET_TRANSPORT_PS_NOT_CONNECTED, GNUNET_TRANSPORT_PS_RECONNECT_ATS, GNUNET_TRANSPORT_PS_RECONNECT_SENT, GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT, GNUNET_TRANSPORT_PS_SYN_RECV_ACK, GNUNET_TRANSPORT_PS_SYN_RECV_ATS, GNUNET_TRANSPORT_PS_SYN_SENT, NeighbourMapEntry::id, master_task(), send_disconnect(), set_state_and_timeout(), NeighbourMapEntry::state, and NeighbourMapEntry::task.

Referenced by GST_neighbours_force_disconnect(), master_task(), send_session_syn_cont(), send_syn(), and set_incoming_quota().

1056 {
1058  "Disconnecting from peer %s in state %s\n",
1059  GNUNET_i2s(&n->id),
1061  /* depending on state, notify neighbour and/or upper layers of this peer
1062  about disconnect */
1063  switch (n->state)
1064  {
1067  /* other peer is completely unaware of us, no need to send DISCONNECT */
1068  free_neighbour(n);
1069  return;
1070 
1072  send_disconnect(n);
1076  break;
1077 
1079  /* we never ACK'ed the other peer's request, no need to send DISCONNECT */
1080  free_neighbour(n);
1081  return;
1082 
1084  /* we DID ACK the other peer's request, must send DISCONNECT */
1085  send_disconnect(n);
1089  break;
1090 
1094  /* we are currently connected, need to send disconnect and do
1095  internal notifications and update statistics */
1096  send_disconnect(n);
1100  break;
1101 
1103  /* Disconnecting while waiting for an ATS address to reconnect,
1104  * cannot send DISCONNECT */
1105  free_neighbour(n);
1106  return;
1107 
1109  /* already disconnected, ignore */
1110  break;
1111 
1113  /* already cleaned up, how did we get here!? */
1114  GNUNET_assert(0);
1115  break;
1116 
1117  default:
1119  "Unhandled state `%s'\n",
1121  GNUNET_break(0);
1122  break;
1123  }
1124  /* schedule timeout to clean up */
1125  if (NULL != n->task)
1128  &master_task,
1129  n);
1130 }
Connection got into trouble, rest of the system still believes it to be up, but we&#39;re getting a new a...
We have some primary connection, but ATS suggested we switch to some alternative; we now sent a SYN m...
Sent SYN over new address (either by ATS telling us to switch addresses or from RECONNECT_ATS); if th...
We&#39;re finished with the disconnect; and are cleaning up the state now! We put the struct into this st...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define DISCONNECT_SENT_TIMEOUT
Time we give plugin to transmit DISCONNECT message before the neighbour entry self-destructs.
Received a SYN, asking ATS about address suggestions.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
static void free_neighbour(struct NeighbourMapEntry *n)
Free a neighbour map entry.
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.
Definition: scheduler.c:1237
Fresh peer or completely disconnected.
struct GNUNET_PeerIdentity id
Identity of this neighbour.
Asked to initiate connection, trying to get address from ATS.
struct GNUNET_SCHEDULER_Task * task
Main task that drives this peer (timeouts, keepalives, etc.).
const char * GNUNET_TRANSPORT_ps2s(enum GNUNET_TRANSPORT_PeerState state)
Convert a transport state to a human readable string.
Sent SYN message to other peer, waiting for SYN_ACK.
enum GNUNET_TRANSPORT_PeerState state
The current state of the peer.
static void set_state_and_timeout(struct NeighbourMapEntry *n, enum GNUNET_TRANSPORT_PeerState s, struct GNUNET_TIME_Absolute timeout)
Set net state and state timeout for this neighbour and notify monitoring.
static void send_disconnect(struct NeighbourMapEntry *n)
Transmit a DISCONNECT message to the other peer.
Disconnect in progress (we&#39;re sending the DISCONNECT message to the other peer; after that is finishe...
#define GNUNET_log(kind,...)
Got our SYN_ACK/ACK, connection is up.
static void master_task(void *cls)
Master task run for every neighbour.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
SYN request from other peer was SYN_ACK&#39;ed, waiting for ACK.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_incoming_quota()

static int set_incoming_quota ( struct NeighbourMapEntry n,
struct GNUNET_BANDWIDTH_Value32NBO  quota 
)
static

Change the incoming quota for the given peer.

Updates our own receive rate and informs the neighbour about the new quota.

Parameters
nneighbour entry to change quota for
quotanew quota
Returns
GNUNET_YES if n is still valid, GNUNET_NO if n was freed

Definition at line 1144 of file gnunet-service-transport_neighbours.c.

References disconnect_neighbour(), gettext_noop, GNUNET_BANDWIDTH_tracker_update_quota(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_log, GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, GST_stats, GNUNET_ATS_SessionQuotaMessage::header, NeighbourMapEntry::id, NeighbourMapEntry::in_tracker, NeighbourMapEntry::primary_address, GNUNET_ATS_SessionQuotaMessage::quota, send_with_session(), NeighbourAddress::session, GNUNET_MessageHeader::size, test_connected(), GNUNET_MessageHeader::type, and GNUNET_BANDWIDTH_Value32NBO::value__.

Referenced by set_primary_address(), and try_run_fast_ats_update().

1146 {
1148  "Setting inbound quota of %u Bps for peer `%s' to all clients\n",
1149  ntohl(quota.value__), GNUNET_i2s(&n->id));
1151  quota);
1152  if (0 != ntohl(quota.value__))
1153  {
1154  struct GNUNET_ATS_SessionQuotaMessage sqm;
1155 
1156  sqm.header.size = htons(sizeof(struct GNUNET_ATS_SessionQuotaMessage));
1157  sqm.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA);
1158  sqm.quota = quota.value__;
1159  if (NULL != n->primary_address.session)
1160  (void)send_with_session(n,
1161  &sqm,
1162  sizeof(sqm),
1163  UINT32_MAX - 1,
1165  GNUNET_NO,
1166  NULL, NULL);
1167  return GNUNET_YES;
1168  }
1170  "Disconnecting peer `%s' due to SET_QUOTA\n",
1171  GNUNET_i2s(&n->id));
1172  if (GNUNET_YES == test_connected(n))
1174  gettext_noop("# disconnects due to quota of 0"),
1175  1, GNUNET_NO);
1177  return GNUNET_NO;
1178 }
struct GNUNET_BANDWIDTH_Tracker in_tracker
Tracker for inbound bandwidth.
void GNUNET_BANDWIDTH_tracker_update_quota(struct GNUNET_BANDWIDTH_Tracker *av, struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit)
Update quota of bandwidth tracker.
Definition: bandwidth.c:526
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA
Message exchanged between transport services to indicate that the sender should limit its transmissio...
Message a peer sends to another when connected to indicate that the other peer should limit transmiss...
#define GNUNET_NO
Definition: gnunet_common.h:78
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
struct GNUNET_MessageHeader header
Header of type GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA.
uint32_t value__
The actual value (bytes per second).
static struct GNUNET_STATISTICS_Handle * GST_stats
Statistics handle.
struct NeighbourAddress primary_address
Primary address we currently use to communicate with the neighbour.
static int test_connected(struct NeighbourMapEntry *n)
Test if we&#39;re connected to the given peer.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_PeerIdentity id
Identity of this neighbour.
struct GNUNET_ATS_Session * session
Active session for this address.
static void disconnect_neighbour(struct NeighbourMapEntry *n)
Disconnect from the given neighbour, clean up the record.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
static struct GNUNET_TIME_Relative send_with_session(struct NeighbourMapEntry *n, const void *msgbuf, size_t msgbuf_size, uint32_t priority, struct GNUNET_TIME_Relative timeout, unsigned int use_keepalive_timeout, GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
Transmit a message using the current session of the given neighbour.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_primary_address()

static void set_primary_address ( struct NeighbourMapEntry n,
const struct GNUNET_HELLO_Address address,
struct GNUNET_ATS_Session session,
struct GNUNET_BANDWIDTH_Value32NBO  bandwidth_in,
struct GNUNET_BANDWIDTH_Value32NBO  bandwidth_out 
)
static

Initialize the primary address of a neighbour.

Parameters
nthe neighbour
addressaddress of the other peer, NULL if other peer connected to us
sessionsession to use (or NULL, in which case an address must be setup)
bandwidth_ininbound quota to be used when connection is up
bandwidth_outoutbound quota to be used when connection is up

Definition at line 1193 of file gnunet-service-transport_neighbours.c.

References NeighbourAddress::address, NeighbourAddress::bandwidth_in, NeighbourAddress::bandwidth_out, free_address(), GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_HELLO_address_cmp(), GNUNET_HELLO_address_copy(), GNUNET_i2s(), GNUNET_log, GNUNET_YES, GST_ats_block_address(), GST_ats_is_known(), GST_plugins_a2s(), GST_validation_set_address_use(), NeighbourMapEntry::id, NeighbourAddress::keep_alive_nonce, neighbours_changed_notification(), NeighbourMapEntry::primary_address, send_outbound_quota_to_clients(), NeighbourAddress::session, set_incoming_quota(), NeighbourMapEntry::state, NeighbourMapEntry::timeout, and GNUNET_BANDWIDTH_Value32NBO::value__.

Referenced by GST_neighbours_handle_session_syn_ack(), and switch_address_bl_check_cont().

1198 {
1199  if (session == n->primary_address.session)
1200  {
1202  GNUNET_YES);
1203  if (n->primary_address.bandwidth_in.value__ != bandwidth_in.value__)
1204  {
1205  n->primary_address.bandwidth_in = bandwidth_in;
1206  if (GNUNET_YES !=
1208  bandwidth_in))
1209  return;
1210  }
1211  if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__)
1212  {
1213  n->primary_address.bandwidth_out = bandwidth_out;
1215  }
1216  return;
1217  }
1218  if ((NULL != n->primary_address.address) &&
1219  (0 == GNUNET_HELLO_address_cmp(address,
1220  n->primary_address.address)))
1221  {
1222  GNUNET_break(0);
1223  return;
1224  }
1225  if (NULL == session)
1226  {
1227  GNUNET_break(0);
1228  GST_ats_block_address(address,
1229  session);
1230  return;
1231  }
1232  if (NULL != n->primary_address.address)
1233  {
1235  "Replacing existing primary address with another one\n");
1237  }
1239  n->primary_address.bandwidth_in = bandwidth_in;
1240  n->primary_address.bandwidth_out = bandwidth_out;
1241  n->primary_address.session = session;
1245  n->primary_address.session));
1246  /* subsystems about address use */
1248  GNUNET_YES);
1249  if (GNUNET_YES !=
1251  bandwidth_in))
1252  return;
1255  "Neighbour `%s' switched to address `%s'\n",
1256  GNUNET_i2s(&n->id),
1257  GST_plugins_a2s(address));
1258 
1261  n->state,
1262  n->timeout,
1265 }
static void neighbours_changed_notification(const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Address *address, enum GNUNET_TRANSPORT_PeerState state, struct GNUNET_TIME_Absolute state_timeout, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
Notify transport clients that a neighbour peer changed its active address.
int GST_ats_is_known(const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session)
Test if ATS knows about this address and session.
struct GNUNET_TIME_Absolute timeout
Time where we should cut the connection (timeout) if we don&#39;t make progress in the state machine (or ...
#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...
uint32_t value__
The actual value (bytes per second).
int GNUNET_HELLO_address_cmp(const struct GNUNET_HELLO_Address *a1, const struct GNUNET_HELLO_Address *a2)
Compare two addresses.
Definition: address.c:130
struct NeighbourAddress primary_address
Primary address we currently use to communicate with the neighbour.
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in
Inbound bandwidth from ATS for this address.
void GST_validation_set_address_use(const struct GNUNET_HELLO_Address *address, int in_use)
Update if we are using an address for a connection actively right now.
struct GNUNET_PeerIdentity id
Identity of this neighbour.
struct GNUNET_ATS_Session * session
Active session for this address.
const char * GST_plugins_a2s(const struct GNUNET_HELLO_Address *address)
Convert a given address to a human-readable format.
struct GNUNET_HELLO_Address * address
Network-level address information.
enum GNUNET_TRANSPORT_PeerState state
The current state of the peer.
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out
Outbound bandwidth from ATS for this address.
static void free_address(struct NeighbourAddress *na)
We don&#39;t need a given neighbour address any more.
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_copy(const struct GNUNET_HELLO_Address *address)
Copy an address struct.
Definition: address.c:109
static int set_incoming_quota(struct NeighbourMapEntry *n, struct GNUNET_BANDWIDTH_Value32NBO quota)
Change the incoming quota for the given peer.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
uint32_t keep_alive_nonce
The current nonce sent in the last keep alive messages.
static void send_outbound_quota_to_clients(struct NeighbourMapEntry *n)
Send information about a new outbound quota to our clients.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
void GST_ats_block_address(const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session)
Temporarily block a valid address for use by ATS for address suggestions.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmit_send_continuation()

static void transmit_send_continuation ( void *  cls,
const struct GNUNET_PeerIdentity receiver,
int  success,
size_t  size_payload,
size_t  physical 
)
static

We're done with our transmission attempt, continue processing.

Parameters
clsthe struct MessageQueue of the message
receiverintended receiver
successwhether it worked or not
size_payloadbytes payload sent
physicalbytes sent on wire

Definition at line 1278 of file gnunet-service-transport_neighbours.c.

References bytes_in_send_queue, MessageQueue::cont, MessageQueue::cont_cls, gettext_noop, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_set(), GNUNET_STATISTICS_update(), GNUNET_SYSERR, GST_stats, NeighbourMapEntry::is_active, lookup_neighbour(), master_task(), MessageQueue::message_buf, MessageQueue::message_buf_size, mq, and NeighbourMapEntry::task.

Referenced by try_transmission_to_peer().

1283 {
1284  struct MessageQueue *mq = cls;
1285  struct NeighbourMapEntry *n;
1286 
1287  if (NULL == (n = lookup_neighbour(receiver)))
1288  {
1289  if (NULL != mq->cont)
1290  mq->cont(mq->cont_cls,
1291  GNUNET_SYSERR /* not connected */,
1292  size_payload,
1293  0);
1294  GNUNET_free(mq);
1295  return; /* disconnect or other error while transmitting, can happen */
1296  }
1297  if (n->is_active == mq)
1298  {
1299  /* this is still "our" neighbour, remove us from its queue
1300  and allow it to send the next message now */
1301  n->is_active = NULL;
1302  if (NULL != n->task)
1305  n);
1306  }
1307  if (bytes_in_send_queue < mq->message_buf_size)
1308  {
1310  "Bytes_in_send_queue `%llu', Message_size %u, result: %s, payload %u, on wire %u\n",
1312  (unsigned int)mq->message_buf_size,
1313  (GNUNET_OK == success) ? "OK" : "FAIL",
1314  (unsigned int)size_payload,
1315  (unsigned int)physical);
1316  GNUNET_break(0);
1317  }
1318 
1319  GNUNET_break(size_payload == mq->message_buf_size);
1322  gettext_noop("# bytes in message queue for other peers"),
1324  GNUNET_NO);
1325  if (GNUNET_OK == success)
1327  gettext_noop("# messages transmitted to other peers"),
1328  1,
1329  GNUNET_NO);
1330  else
1332  gettext_noop
1333  ("# transmission failures for messages to other peers"),
1334  1, GNUNET_NO);
1336  "Sending message to `%s' of type %u with %u bytes was a %s\n",
1337  GNUNET_i2s(receiver),
1338  ntohs(((struct GNUNET_MessageHeader *)mq->message_buf)->type),
1339  (unsigned int)mq->message_buf_size,
1340  (success == GNUNET_OK) ? "success" : "FAILURE");
1341  if (NULL != mq->cont)
1342  mq->cont(mq->cont_cls,
1343  success,
1344  size_payload,
1345  physical);
1346  GNUNET_free(mq);
1347 }
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_STATISTICS_Handle * GST_stats
Statistics handle.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1264
void * cont_cls
Closure for cont.
For each neighbour we keep a list of messages that we still want to transmit to the neighbour...
struct GNUNET_SCHEDULER_Task * task
Main task that drives this peer (timeouts, keepalives, etc.).
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
static struct NeighbourMapEntry * lookup_neighbour(const struct GNUNET_PeerIdentity *pid)
Lookup a neighbour entry in the neighbours hash map.
static unsigned long long bytes_in_send_queue
Number of bytes we have currently queued for transmission.
const char * message_buf
The message(s) we want to transmit, GNUNET_MessageHeader(s) stuck together in memory.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
GST_NeighbourSendContinuation cont
Function to call once we&#39;re done.
struct MessageQueue * is_active
Are we currently trying to send a message? If so, which one?
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define GNUNET_log(kind,...)
Header for all communications.
static void master_task(void *cls)
Master task run for every neighbour.
size_t message_buf_size
Size of the message buf.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
Here is the call graph for this function:
Here is the caller graph for this function:

◆ try_transmission_to_peer()

static void try_transmission_to_peer ( struct NeighbourMapEntry n)
static

Check the message list for the given neighbour and if we can send a message, do so.

This function should only be called if the connection is at least generally ready for transmission. While we will only send one message at a time, no bandwidth quota management is performed here. If a message was given to the plugin, the continuation will automatically re-schedule the 'master' task once the next message might be transmitted.

Parameters
ntarget peer for which to transmit

Definition at line 1362 of file gnunet-service-transport_neighbours.c.

References NeighbourAddress::address, GNUNET_HELLO_Address::address_length, gettext_noop, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_TIME_absolute_get_remaining(), GST_stats, NeighbourMapEntry::id, NeighbourMapEntry::is_active, MessageQueue::message_buf, MessageQueue::message_buf_size, NeighbourMapEntry::messages_head, NeighbourMapEntry::messages_tail, mq, NeighbourMapEntry::primary_address, GNUNET_TIME_Relative::rel_value_us, send_with_session(), NeighbourAddress::session, MessageQueue::timeout, and transmit_send_continuation().

Referenced by master_task().

1363 {
1364  struct MessageQueue *mq;
1366 
1367  if (NULL == n->primary_address.address)
1368  {
1369  /* no address, why are we here? */
1370  GNUNET_break(0);
1371  return;
1372  }
1373  if ((0 == n->primary_address.address->address_length) &&
1374  (NULL == n->primary_address.session))
1375  {
1376  /* no address, why are we here? */
1377  GNUNET_break(0);
1378  return;
1379  }
1380  if (NULL != n->is_active)
1381  {
1382  /* transmission already pending */
1383  return;
1384  }
1385 
1386  /* timeout messages from the queue that are past their due date */
1387  while (NULL != (mq = n->messages_head))
1388  {
1390  if (timeout.rel_value_us > 0)
1391  break;
1393  gettext_noop("# messages timed out while in transport queue"),
1394  1,
1395  GNUNET_NO);
1397  n->messages_tail,
1398  mq);
1399  n->is_active = mq;
1401  &n->id,
1402  GNUNET_SYSERR,
1403  mq->message_buf_size,
1404  0); /* timeout */
1405  }
1406  if (NULL == mq)
1407  return; /* no more messages */
1408  if (NULL == n->primary_address.address)
1409  {
1410  /* transmit_send_continuation() caused us to drop session,
1411  can't try transmission anymore. */
1412  return;
1413  }
1414 
1415 
1417  n->messages_tail,
1418  mq);
1419  n->is_active = mq;
1420 
1422  "Giving message with %u bytes to plugin session %p\n",
1423  (unsigned int)mq->message_buf_size,
1425  (void)send_with_session(n,
1426  mq->message_buf,
1427  mq->message_buf_size,
1428  0 /* priority */,
1429  timeout,
1430  GNUNET_NO,
1432  mq);
1433 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
size_t address_length
Number of bytes in address.
uint64_t rel_value_us
The actual value.
struct GNUNET_TIME_Absolute timeout
At what time should we fail?
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct MessageQueue * messages_tail
Tail of list of messages we would like to send to this peer; must contain at most one message per cli...
static struct GNUNET_STATISTICS_Handle * GST_stats
Statistics handle.
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:114
struct NeighbourAddress primary_address
Primary address we currently use to communicate with the neighbour.
For each neighbour we keep a list of messages that we still want to transmit to the neighbour...
struct GNUNET_PeerIdentity id
Identity of this neighbour.
struct GNUNET_ATS_Session * session
Active session for this address.
struct MessageQueue * messages_head
Head of list of messages we would like to send to this peer; must contain at most one message per cli...
const char * message_buf
The message(s) we want to transmit, GNUNET_MessageHeader(s) stuck together in memory.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_HELLO_Address * address
Network-level address information.
struct MessageQueue * is_active
Are we currently trying to send a message? If so, which one?
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define GNUNET_log(kind,...)
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
static void transmit_send_continuation(void *cls, const struct GNUNET_PeerIdentity *receiver, int success, size_t size_payload, size_t physical)
We&#39;re done with our transmission attempt, continue processing.
size_t message_buf_size
Size of the message buf.
static struct GNUNET_TIME_Relative send_with_session(struct NeighbourMapEntry *n, const void *msgbuf, size_t msgbuf_size, uint32_t priority, struct GNUNET_TIME_Relative timeout, unsigned int use_keepalive_timeout, GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
Transmit a message using the current session of the given neighbour.
Time for relative time used by GNUnet, in microseconds.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_keepalive()

static void send_keepalive ( struct NeighbourMapEntry n)
static

Send keepalive message to the neighbour.

Must only be called if we are on 'connected' state or while trying to switch addresses. Will internally determine if a keepalive is truly needed (so can always be called).

Parameters
nneighbour that went idle and needs a keepalive

Definition at line 1445 of file gnunet-service-transport_neighbours.c.

References NeighbourMapEntry::expect_latency_response, gettext_noop, GNUNET_assert, GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_random_u32(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TRANSPORT_PS_CONNECTED, GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT, GNUNET_YES, GST_stats, GNUNET_ATS_SessionKeepAliveMessage::header, NeighbourMapEntry::id, NeighbourAddress::keep_alive_nonce, NeighbourMapEntry::keep_alive_time, NeighbourMapEntry::last_keep_alive_time, GNUNET_ATS_SessionKeepAliveMessage::nonce, NeighbourMapEntry::primary_address, GNUNET_TIME_Relative::rel_value_us, send_with_session(), GNUNET_MessageHeader::size, NeighbourMapEntry::state, and GNUNET_MessageHeader::type.

Referenced by master_task().

1446 {
1449  uint32_t nonce;
1450 
1454  return; /* no keepalive needed at this time */
1455 
1456  nonce = 0; /* 0 indicates 'not set' */
1457  while (0 == nonce)
1459  UINT32_MAX);
1460 
1462  "Sending KEEPALIVE to peer `%s' with nonce %u\n",
1463  GNUNET_i2s(&n->id),
1464  nonce);
1465  m.header.size = htons(sizeof(struct GNUNET_ATS_SessionKeepAliveMessage));
1467  m.nonce = htonl(nonce);
1468 
1470  &m,
1471  sizeof(m),
1472  UINT32_MAX /* priority */,
1474  GNUNET_YES,
1475  NULL, NULL);
1477  gettext_noop("# KEEPALIVES sent"),
1478  1,
1479  GNUNET_NO);
1480  n->primary_address.keep_alive_nonce = nonce;
1484 }
We have some primary connection, but ATS suggested we switch to some alternative; we now sent a SYN m...
uint64_t rel_value_us
The actual value.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:246
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:99
struct GNUNET_TIME_Absolute last_keep_alive_time
At what time did we sent the last keep-alive message? Used to calculate round-trip time ("latency")...
static struct GNUNET_STATISTICS_Handle * GST_stats
Statistics handle.
struct GNUNET_TIME_Absolute keep_alive_time
At what time should we sent the next keep-alive message?
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:114
struct NeighbourAddress primary_address
Primary address we currently use to communicate with the neighbour.
Randomness for IVs etc.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_PeerIdentity id
Identity of this neighbour.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE
Message send by a peer to notify the other to keep the session alive and measure latency in a regular...
Message a peer sends to another when connected to indicate that a session is in use and the peer is s...
enum GNUNET_TRANSPORT_PeerState state
The current state of the peer.
int expect_latency_response
Did we sent an KEEP_ALIVE message and are we expecting a response?
#define GNUNET_log(kind,...)
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
#define GNUNET_YES
Definition: gnunet_common.h:77
Got our SYN_ACK/ACK, connection is up.
static struct GNUNET_TIME_Relative send_with_session(struct NeighbourMapEntry *n, const void *msgbuf, size_t msgbuf_size, uint32_t priority, struct GNUNET_TIME_Relative timeout, unsigned int use_keepalive_timeout, GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
Transmit a message using the current session of the given neighbour.
uint32_t keep_alive_nonce
The current nonce sent in the last keep alive messages.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Time for relative time used by GNUnet, in microseconds.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_neighbours_keepalive()

void GST_neighbours_keepalive ( const struct GNUNET_PeerIdentity neighbour,
const struct GNUNET_MessageHeader m 
)

Keep the connection to the given neighbour alive longer, we received a KEEPALIVE (or equivalent); send a response.

Parameters
neighbourneighbour to keep alive (by sending keep alive response)
mthe keep alive message containing the nonce to respond to

Definition at line 1495 of file gnunet-service-transport_neighbours.c.

References gettext_noop, GNUNET_break_op, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, GST_stats, GNUNET_ATS_SessionKeepAliveMessage::header, NeighbourMapEntry::id, lookup_neighbour(), GNUNET_ATS_SessionKeepAliveMessage::nonce, NeighbourMapEntry::primary_address, send_with_session(), NeighbourAddress::session, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

Referenced by GST_receive_callback().

1497 {
1498  struct NeighbourMapEntry *n;
1499  const struct GNUNET_ATS_SessionKeepAliveMessage *msg_in;
1501 
1502  if (sizeof(struct GNUNET_ATS_SessionKeepAliveMessage) != ntohs(m->size))
1503  {
1504  GNUNET_break_op(0);
1505  return;
1506  }
1507 
1508  msg_in = (const struct GNUNET_ATS_SessionKeepAliveMessage *)m;
1509  if (NULL == (n = lookup_neighbour(neighbour)))
1510  {
1512  gettext_noop
1513  ("# KEEPALIVE messages discarded (peer unknown)"),
1514  1, GNUNET_NO);
1515  return;
1516  }
1517  if (NULL == n->primary_address.session)
1518  {
1520  gettext_noop
1521  ("# KEEPALIVE messages discarded (no session)"),
1522  1, GNUNET_NO);
1523  return;
1524  }
1525 
1527  "Received KEEPALIVE request from peer `%s' with nonce %u\n",
1528  GNUNET_i2s(&n->id),
1529  ntohl(msg_in->nonce));
1531  gettext_noop("# KEEPALIVES received in good order"),
1532  1,
1533  GNUNET_NO);
1534 
1535  /* send reply to allow neighbour to measure latency */
1536  msg.header.size = htons(sizeof(struct GNUNET_ATS_SessionKeepAliveMessage));
1538  msg.nonce = msg_in->nonce;
1539  (void)send_with_session(n,
1540  &msg,
1541  sizeof(struct GNUNET_ATS_SessionKeepAliveMessage),
1542  UINT32_MAX /* priority */,
1544  GNUNET_YES,
1545  NULL, NULL);
1546 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define GNUNET_NO
Definition: gnunet_common.h:78
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE
Response to a GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE message to measure latency in a regular...
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
static struct GNUNET_STATISTICS_Handle * GST_stats
Statistics handle.
struct NeighbourAddress primary_address
Primary address we currently use to communicate with the neighbour.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_PeerIdentity id
Identity of this neighbour.
struct GNUNET_ATS_Session * session
Active session for this address.
static struct NeighbourMapEntry * lookup_neighbour(const struct GNUNET_PeerIdentity *pid)
Lookup a neighbour entry in the neighbours hash map.
Message a peer sends to another when connected to indicate that a session is in use and the peer is s...
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
static struct GNUNET_TIME_Relative send_with_session(struct NeighbourMapEntry *n, const void *msgbuf, size_t msgbuf_size, uint32_t priority, struct GNUNET_TIME_Relative timeout, unsigned int use_keepalive_timeout, GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
Transmit a message using the current session of the given neighbour.
uint32_t nonce
A nonce to identify the session the keep alive is used for.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_neighbours_keepalive_response()

void GST_neighbours_keepalive_response ( const struct GNUNET_PeerIdentity neighbour,
const struct GNUNET_MessageHeader m 
)

We received a KEEP_ALIVE_RESPONSE message and use this to calculate latency to this peer.

Pass the updated information (existing ats plus calculated latency) to ATS.

Parameters
neighbourneighbour to keep alive
mthe message containing the keep alive response

Definition at line 1558 of file gnunet-service-transport_neighbours.c.

References NeighbourAddress::address, GNUNET_TRANSPORT_PluginFunctions::cls, NeighbourMapEntry::expect_latency_response, gettext_noop, GNUNET_break, GNUNET_break_op, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_relative_divide(), GNUNET_TIME_relative_to_absolute(), GNUNET_TRANSPORT_PS_CONNECTED, GNUNET_YES, GST_ats_update_delay(), GST_plugins_find(), GST_stats, NeighbourMapEntry::id, NeighbourAddress::keep_alive_nonce, NeighbourMapEntry::last_keep_alive_time, lookup_neighbour(), msg, GNUNET_ATS_SessionKeepAliveMessage::nonce, NeighbourMapEntry::primary_address, NeighbourAddress::session, set_state_and_timeout(), GNUNET_MessageHeader::size, NeighbourMapEntry::state, GNUNET_HELLO_Address::transport_name, and GNUNET_TRANSPORT_PluginFunctions::update_session_timeout.

Referenced by GST_receive_callback().

1560 {
1561  struct NeighbourMapEntry *n;
1563  struct GNUNET_TRANSPORT_PluginFunctions *papi;
1564  struct GNUNET_TIME_Relative latency;
1565 
1566  if (sizeof(struct GNUNET_ATS_SessionKeepAliveMessage) != ntohs(m->size))
1567  {
1568  GNUNET_break_op(0);
1569  return;
1570  }
1571 
1572  msg = (const struct GNUNET_ATS_SessionKeepAliveMessage *)m;
1573  if (NULL == (n = lookup_neighbour(neighbour)))
1574  {
1576  gettext_noop("# KEEPALIVE_RESPONSEs discarded (not connected)"),
1577  1,
1578  GNUNET_NO);
1579  return;
1580  }
1581  if ((GNUNET_TRANSPORT_PS_CONNECTED != n->state) ||
1583  {
1585  gettext_noop("# KEEPALIVE_RESPONSEs discarded (not expected)"),
1586  1,
1587  GNUNET_NO);
1588  return;
1589  }
1590  if (NULL == n->primary_address.address)
1591  {
1593  gettext_noop("# KEEPALIVE_RESPONSEs discarded (address changed)"),
1594  1,
1595  GNUNET_NO);
1596  return;
1597  }
1598  if (n->primary_address.keep_alive_nonce != ntohl(msg->nonce))
1599  {
1600  if (0 == n->primary_address.keep_alive_nonce)
1602  gettext_noop("# KEEPALIVE_RESPONSEs discarded (no nonce)"),
1603  1,
1604  GNUNET_NO);
1605  else
1607  gettext_noop("# KEEPALIVE_RESPONSEs discarded (bad nonce)"),
1608  1,
1609  GNUNET_NO);
1610  return;
1611  }
1613  gettext_noop("# KEEPALIVE_RESPONSEs received (OK)"),
1614  1,
1615  GNUNET_NO);
1616 
1617 
1618  /* Update session timeout here */
1619  if (NULL != (papi = GST_plugins_find(n->primary_address.address->transport_name)))
1620  {
1622  "Updating session for peer `%s' for session %p\n",
1623  GNUNET_i2s(&n->id),
1625  papi->update_session_timeout(papi->cls,
1626  &n->id,
1628  }
1629  else
1630  {
1631  GNUNET_break(0);
1632  }
1633 
1637  n->state,
1639 
1642  "Received KEEPALIVE_RESPONSE from peer `%s', latency is %s\n",
1643  GNUNET_i2s(&n->id),
1645  GNUNET_YES));
1648  2));
1649 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:246
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
#define GNUNET_NO
Definition: gnunet_common.h:78
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
GNUNET_TRANSPORT_UpdateSessionTimeout update_session_timeout
Function that will be called whenever the transport service wants to notify the plugin that a session...
struct GNUNET_TIME_Absolute last_keep_alive_time
At what time did we sent the last keep-alive message? Used to calculate round-trip time ("latency")...
static struct GNUNET_STATISTICS_Handle * GST_stats
Statistics handle.
void * cls
Closure for all of the callbacks.
struct NeighbourAddress primary_address
Primary address we currently use to communicate with the neighbour.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:686
const char * transport_name
Name of the transport plugin enabling the communication using this address.
struct GNUNET_PeerIdentity id
Identity of this neighbour.
struct GNUNET_ATS_Session * session
Active session for this address.
struct GNUNET_TRANSPORT_PluginFunctions * GST_plugins_find(const char *name)
Obtain the plugin API based on a plugin name.
static struct NeighbourMapEntry * lookup_neighbour(const struct GNUNET_PeerIdentity *pid)
Lookup a neighbour entry in the neighbours hash map.
struct GNUNET_HELLO_Address * address
Network-level address information.
Message a peer sends to another when connected to indicate that a session is in use and the peer is s...
enum GNUNET_TRANSPORT_PeerState state
The current state of the peer.
static void set_state_and_timeout(struct NeighbourMapEntry *n, enum GNUNET_TRANSPORT_PeerState s, struct GNUNET_TIME_Absolute timeout)
Set net state and state timeout for this neighbour and notify monitoring.
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don&#39;t receive messages from the peer...
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:373
int expect_latency_response
Did we sent an KEEP_ALIVE message and are we expecting a response?
void GST_ats_update_delay(const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Relative delay)
Notify ATS about delay changes to properties of an address.
#define GNUNET_log(kind,...)
struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Divide relative time by a given factor.
Definition: time.c:525
#define GNUNET_YES
Definition: gnunet_common.h:77
Got our SYN_ACK/ACK, connection is up.
uint32_t keep_alive_nonce
The current nonce sent in the last keep alive messages.
uint32_t nonce
A nonce to identify the session the keep alive is used for.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Time for relative time used by GNUnet, in microseconds.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_neighbours_calculate_receive_delay()

struct GNUNET_TIME_Relative GST_neighbours_calculate_receive_delay ( const struct GNUNET_PeerIdentity sender,
ssize_t  size,
int *  do_forward 
)

We have received a message from the given sender.

How long should we delay before receiving more? (Also used to keep the peer marked as live).

Parameters
sendersender of the message
sizesize of the message
do_forwardset to GNUNET_YES if the message should be forwarded to clients GNUNET_NO if the neighbour is not connected or violates the quota, GNUNET_SYSERR if the connection is not fully up yet
Returns
how long to wait before reading more from this sender

Definition at line 1665 of file gnunet-service-transport_neighbours.c.

References GNUNET_BANDWIDTH_Tracker::available_bytes_per_s__, GNUNET_BANDWIDTH_Tracker::consumption_since_last_update__, gettext_noop, GNUNET_BANDWIDTH_tracker_consume(), GNUNET_BANDWIDTH_tracker_get_delay(), GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TIME_UNIT_ZERO, GNUNET_YES, GST_stats, NeighbourMapEntry::in_tracker, lookup_neighbour(), NeighbourMapEntry::quota_violation_count, QUOTA_VIOLATION_DROP_THRESHOLD, GNUNET_TIME_Relative::rel_value_us, ret, size, and test_connected().

Referenced by inbound_bw_tracker_update(), and process_payload().

1668 {
1669  struct NeighbourMapEntry *n;
1670  struct GNUNET_TIME_Relative ret;
1671 
1672  if (NULL == neighbours)
1673  {
1674  *do_forward = GNUNET_NO;
1675  return GNUNET_TIME_UNIT_FOREVER_REL; /* This can happen during shutdown */
1676  }
1677  if (NULL == (n = lookup_neighbour(sender)))
1678  {
1680  gettext_noop("# messages discarded due to lack of neighbour record"),
1681  1,
1682  GNUNET_NO);
1683  *do_forward = GNUNET_NO;
1684  return GNUNET_TIME_UNIT_ZERO;
1685  }
1686  if (!test_connected(n))
1687  {
1688  *do_forward = GNUNET_SYSERR;
1689  return GNUNET_TIME_UNIT_ZERO;
1690  }
1692  {
1693  n->quota_violation_count++;
1695  "Bandwidth quota (%u b/s) violation detected (total of %u).\n",
1698  /* Discount 32k per violation */
1700  }
1701  else
1702  {
1703  if (n->quota_violation_count > 0)
1704  {
1705  /* try to add 32k back */
1707  n->quota_violation_count--;
1708  }
1709  }
1711  {
1713  gettext_noop
1714  ("# bandwidth quota violations by other peers"),
1715  1, GNUNET_NO);
1716  *do_forward = GNUNET_NO;
1718  }
1719  *do_forward = GNUNET_YES;
1721  if (ret.rel_value_us > 0)
1722  {
1724  "Throttling read (%lld bytes excess at %u b/s), waiting %s before reading more.\n",
1726  (unsigned int)n->in_tracker.available_bytes_per_s__,
1729  gettext_noop("# ms throttling suggested"),
1730  (int64_t)ret.rel_value_us / 1000LL,
1731  GNUNET_NO);
1732  }
1733  return ret;
1734 }
static struct GNUNET_CONTAINER_MultiPeerMap * neighbours
Hash map from peer identities to the respective struct NeighbourMapEntry.
int GNUNET_BANDWIDTH_tracker_consume(struct GNUNET_BANDWIDTH_Tracker *av, ssize_t size)
Notify the tracker that a certain number of bytes of bandwidth have been consumed.
Definition: bandwidth.c:402
unsigned int quota_violation_count
How often has the other peer (recently) violated the inbound traffic limit? Incremented by 10 per vio...
struct GNUNET_BANDWIDTH_Tracker in_tracker
Tracker for inbound bandwidth.
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static int ret
Final status code.
Definition: gnunet-arm.c:89
static struct GNUNET_STATISTICS_Handle * GST_stats
Statistics handle.
int64_t consumption_since_last_update__
Number of bytes consumed since we last updated the tracker.
static int test_connected(struct NeighbourMapEntry *n)
Test if we&#39;re connected to the given peer.
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:686
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT
How long do we delay reading more from a peer after a quota violation?
static struct NeighbourMapEntry * lookup_neighbour(const struct GNUNET_PeerIdentity *pid)
Lookup a neighbour entry in the neighbours hash map.
struct GNUNET_TIME_Relative GNUNET_BANDWIDTH_tracker_get_delay(struct GNUNET_BANDWIDTH_Tracker *av, size_t size)
Compute how long we should wait until consuming size bytes of bandwidth in order to stay within the g...
Definition: bandwidth.c:458
#define QUOTA_VIOLATION_DROP_THRESHOLD
How often must a peer violate bandwidth quotas before we start to simply drop its messages...
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:66
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
uint32_t available_bytes_per_s__
Bandwidth limit to enforce in bytes per second.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
Time for relative time used by GNUnet, in microseconds.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_neighbours_send()

void GST_neighbours_send ( const struct GNUNET_PeerIdentity target,
const void *  msg,
size_t  msg_size,
struct GNUNET_TIME_Relative  timeout,
GST_NeighbourSendContinuation  cont,
void *  cont_cls 
)

Transmit a message to the given target using the active connection.

Parameters
targetdestination
msgmessage to send
msg_sizenumber of bytes in msg
timeoutwhen to fail with timeout
contfunction to call when done
cont_clsclosure for cont

Definition at line 1748 of file gnunet-service-transport_neighbours.c.

References bytes_in_send_queue, MessageQueue::cont, MessageQueue::cont_cls, gettext_noop, GNUNET_break, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_NO, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_set(), GNUNET_SYSERR, GNUNET_TIME_relative_to_absolute(), GNUNET_YES, GST_stats, lookup_neighbour(), master_task(), MessageQueue::message_buf, MessageQueue::message_buf_size, NeighbourMapEntry::messages_head, NeighbourMapEntry::messages_tail, mq, NeighbourMapEntry::task, test_connected(), and MessageQueue::timeout.

Referenced by GST_manipulation_send(), send_delayed(), and transmit_our_hello().

1754 {
1755  struct NeighbourMapEntry *n;
1756  struct MessageQueue *mq;
1757 
1758  /* All ove these cases should never happen; they are all API violations.
1759  But we check anyway, just to be sure. */
1760  if (NULL == (n = lookup_neighbour(target)))
1761  {
1762  GNUNET_break(0);
1763  if (NULL != cont)
1764  cont(cont_cls,
1765  GNUNET_SYSERR,
1766  msg_size,
1767  0);
1768  return;
1769  }
1770  if (GNUNET_YES != test_connected(n))
1771  {
1772  GNUNET_break(0);
1773  if (NULL != cont)
1774  cont(cont_cls,
1775  GNUNET_SYSERR,
1776  msg_size,
1777  0);
1778  return;
1779  }
1780  bytes_in_send_queue += msg_size;
1782  gettext_noop
1783  ("# bytes in message queue for other peers"),
1785  mq = GNUNET_malloc(sizeof(struct MessageQueue) + msg_size);
1786  mq->cont = cont;
1787  mq->cont_cls = cont_cls;
1788  GNUNET_memcpy(&mq[1], msg, msg_size);
1789  mq->message_buf = (const char *)&mq[1];
1790  mq->message_buf_size = msg_size;
1792 
1794  "Enqueueing %u bytes to send to peer %s\n",
1795  (unsigned int)msg_size,
1796  GNUNET_i2s(target));
1798  n->messages_tail,
1799  mq);
1800  if (NULL != n->task)
1803 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:246
struct GNUNET_TIME_Absolute timeout
At what time should we fail?
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct MessageQueue * messages_tail
Tail of list of messages we would like to send to this peer; must contain at most one message per cli...
static struct GNUNET_STATISTICS_Handle * GST_stats
Statistics handle.
static int test_connected(struct NeighbourMapEntry *n)
Test if we&#39;re connected to the given peer.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1264
void * cont_cls
Closure for cont.
For each neighbour we keep a list of messages that we still want to transmit to the neighbour...
struct MessageQueue * messages_head
Head of list of messages we would like to send to this peer; must contain at most one message per cli...
struct GNUNET_SCHEDULER_Task * task
Main task that drives this peer (timeouts, keepalives, etc.).
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
static struct NeighbourMapEntry * lookup_neighbour(const struct GNUNET_PeerIdentity *pid)
Lookup a neighbour entry in the neighbours hash map.
static unsigned long long bytes_in_send_queue
Number of bytes we have currently queued for transmission.
const char * message_buf
The message(s) we want to transmit, GNUNET_MessageHeader(s) stuck together in memory.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
GST_NeighbourSendContinuation cont
Function to call once we&#39;re done.
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
static void master_task(void *cls)
Master task run for every neighbour.
size_t message_buf_size
Size of the message buf.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_malloc(size)
Wrapper around malloc.
#define gettext_noop(String)
Definition: gettext.h:69
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_session_syn_cont()

static void send_session_syn_cont ( void *  cls,
const struct GNUNET_PeerIdentity target,
int  result,
size_t  size_payload,
size_t  size_on_wire 
)
static

Continuation called from our attempt to transmitted our GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN to the specified target.

Continue processing based on the result. Specifically, if we failed to transmit, discard the address we used.

Parameters
clsNULL
targetwhich peer received the transmission
resultGNUNET_OK if sending worked
size_payloadhow many bytes of payload were sent (ignored)
size_on_wirehow much bandwidth was consumed on the wire (ignored)

Definition at line 1819 of file gnunet-service-transport_neighbours.c.

References _, NeighbourMapEntry::alternative_address, ATS_RESPONSE_TIMEOUT, disconnect_neighbour(), FAST_RECONNECT_TIMEOUT, free_address(), gettext_noop, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_TIME_relative_to_absolute(), GNUNET_TRANSPORT_PS_CONNECTED, GNUNET_TRANSPORT_PS_INIT_ATS, GNUNET_TRANSPORT_PS_RECONNECT_ATS, GNUNET_TRANSPORT_PS_RECONNECT_SENT, GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT, GNUNET_TRANSPORT_PS_SYN_SENT, GST_stats, lookup_neighbour(), set_state_and_timeout(), NeighbourMapEntry::state, and unset_primary_address().

Referenced by send_syn().

1824 {
1825  struct NeighbourMapEntry *n;
1826 
1827  (void)cls;
1828  (void)size_payload;
1829  (void)size_on_wire;
1830  n = lookup_neighbour(target);
1831  if (NULL == n)
1832  {
1833  /* SYN continuation was called after neighbor was freed,
1834  * for example due to a time out for the state or the session
1835  * used was already terminated: nothing to do here... */
1836  return;
1837  }
1838 
1839  if ((GNUNET_TRANSPORT_PS_SYN_SENT != n->state) &&
1842  {
1843  /* SYN continuation was called after neighbor changed state,
1844  * for example due to a time out for the state or the session
1845  * used was already terminated: nothing to do here... */
1846  return;
1847  }
1848  if (GNUNET_OK == result)
1849  return;
1850 
1852  _("Failed to send SYN message to peer `%s'\n"),
1853  GNUNET_i2s(target));
1854  switch (n->state)
1855  {
1857  /* Remove address and request an additional one */
1862  break;
1863 
1865  /* Remove address and request an additional one */
1870  break;
1871 
1873  /* Remove address and request and go back to primary address */
1875  gettext_noop("# Failed attempts to switch addresses (failed to send SYN CONT)"),
1876  1,
1877  GNUNET_NO);
1879  "Switch failed, cleaning up alternative address\n");
1884  break;
1885 
1886  default:
1888  break;
1889  }
1890 }
Connection got into trouble, rest of the system still believes it to be up, but we&#39;re getting a new a...
We have some primary connection, but ATS suggested we switch to some alternative; we now sent a SYN m...
Sent SYN over new address (either by ATS telling us to switch addresses or from RECONNECT_ATS); if th...
struct NeighbourAddress alternative_address
Alternative address currently under consideration for communicating with the neighbour.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:246
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static struct GNUNET_STATISTICS_Handle * GST_stats
Statistics handle.
#define FAST_RECONNECT_TIMEOUT
How long are we willing to wait for a successful reconnect if an existing connection went down...
static int result
Global testing status.
Asked to initiate connection, trying to get address from ATS.
static struct NeighbourMapEntry * lookup_neighbour(const struct GNUNET_PeerIdentity *pid)
Lookup a neighbour entry in the neighbours hash map.
Sent SYN message to other peer, waiting for SYN_ACK.
enum GNUNET_TRANSPORT_PeerState state
The current state of the peer.
static void set_state_and_timeout(struct NeighbourMapEntry *n, enum GNUNET_TRANSPORT_PeerState s, struct GNUNET_TIME_Absolute timeout)
Set net state and state timeout for this neighbour and notify monitoring.
static void free_address(struct NeighbourAddress *na)
We don&#39;t need a given neighbour address any more.
static void unset_primary_address(struct NeighbourMapEntry *n)
Clear the primary address of a neighbour since this address is not valid anymore and notify monitorin...
static void disconnect_neighbour(struct NeighbourMapEntry *n)
Disconnect from the given neighbour, clean up the record.
#define ATS_RESPONSE_TIMEOUT
How long are we willing to wait for a response from ATS before timing out?
#define GNUNET_log(kind,...)
Got our SYN_ACK/ACK, connection is up.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_syn()

static void send_syn ( struct NeighbourAddress na)
static

Send a SYN message via the given address.

Parameters
naaddress to use

Definition at line 1899 of file gnunet-service-transport_neighbours.c.

References _, NeighbourAddress::address, NeighbourMapEntry::alternative_address, ATS_RESPONSE_TIMEOUT, GNUNET_TRANSPORT_PluginFunctions::cls, NeighbourAddress::connect_timestamp, disconnect_neighbour(), FAST_RECONNECT_TIMEOUT, free_address(), gettext_noop, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_i2s(), GNUNET_log, GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_hton(), GNUNET_TIME_relative_to_absolute(), GNUNET_TRANSPORT_PS_CONNECTED, GNUNET_TRANSPORT_PS_INIT_ATS, GNUNET_TRANSPORT_PS_RECONNECT_ATS, GNUNET_TRANSPORT_PS_RECONNECT_SENT, GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT, GNUNET_TRANSPORT_PS_SYN_SENT, GST_neighbours_notify_data_sent(), GST_plugins_a2s(), GST_plugins_find(), GST_stats, TransportSynMessage::header, lookup_neighbour(), GNUNET_HELLO_Address::peer, NeighbourMapEntry::primary_address, TransportSynMessage::reserved, GNUNET_TRANSPORT_PluginFunctions::send, send_session_syn_cont(), NeighbourAddress::session, set_state_and_timeout(), SETUP_CONNECTION_TIMEOUT, GNUNET_MessageHeader::size, NeighbourMapEntry::state, TransportSynMessage::timestamp, GNUNET_HELLO_Address::transport_name, GNUNET_MessageHeader::type, and unset_primary_address().

Referenced by switch_address_bl_check_cont().

1900 {
1901  struct GNUNET_TRANSPORT_PluginFunctions *papi;
1902  struct TransportSynMessage connect_msg;
1903  struct NeighbourMapEntry *n;
1904 
1905  GNUNET_assert(NULL != na->session);
1907  "Sending SYN message to peer `%s' at %s\n",
1908  GNUNET_i2s(&na->address->peer),
1909  GST_plugins_a2s(na->address));
1910 
1912  GNUNET_assert(NULL != papi);
1914  gettext_noop
1915  ("# SYN messages sent"),
1916  1, GNUNET_NO);
1918  connect_msg.header.size = htons(sizeof(struct TransportSynMessage));
1919  connect_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN);
1920  connect_msg.reserved = htonl(0);
1921  connect_msg.timestamp = GNUNET_TIME_absolute_hton(na->connect_timestamp);
1922  if (-1 ==
1923  papi->send(papi->cls,
1924  na->session,
1925  (const char *)&connect_msg,
1926  sizeof(struct TransportSynMessage),
1927  UINT_MAX,
1929  &send_session_syn_cont, NULL))
1930  {
1932  _("Failed to transmit SYN message to %s\n"),
1933  GST_plugins_a2s(na->address));
1934  n = lookup_neighbour(&na->address->peer);
1935  if (NULL == n)
1936  {
1937  GNUNET_break(0);
1938  return;
1939  }
1940  switch (n->state)
1941  {
1943  /* Remove address and request and additional one */
1944  GNUNET_assert(na == &n->primary_address);
1949  /* Hard failure to send the SYN message with this address:
1950  Destroy address and session */
1951  break;
1952 
1954  /* Remove address and request an additional one */
1955  GNUNET_assert(na == &n->primary_address);
1960  break;
1961 
1965  gettext_noop("# Failed attempts to switch addresses (failed to send SYN)"),
1966  1,
1967  GNUNET_NO);
1968  /* Remove address and request an additional one */
1970  "Switch failed, cleaning up alternative address\n");
1975  break;
1976 
1977  default:
1978  GNUNET_break(0);
1980  break;
1981  }
1982  return;
1983  }
1985  na->session,
1986  sizeof(struct TransportSynMessage));
1987 }
Connection got into trouble, rest of the system still believes it to be up, but we&#39;re getting a new a...
We have some primary connection, but ATS suggested we switch to some alternative; we now sent a SYN m...
Sent SYN over new address (either by ATS telling us to switch addresses or from RECONNECT_ATS); if th...
struct NeighbourAddress alternative_address
Alternative address currently under consideration for communicating with the neighbour.
GNUNET_TRANSPORT_TransmitFunction send
Function that the transport service will use to transmit data to another peer.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:246
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
Message a peer sends to another to indicate that it intends to setup a connection/session for data ex...
static struct GNUNET_STATISTICS_Handle * GST_stats
Statistics handle.
void * cls
Closure for all of the callbacks.
struct NeighbourAddress primary_address
Primary address we currently use to communicate with the neighbour.
#define FAST_RECONNECT_TIMEOUT
How long are we willing to wait for a successful reconnect if an existing connection went down...
#define SETUP_CONNECTION_TIMEOUT
How long are we willing to wait for an ACK from the other peer before giving up on our connect operat...
struct GNUNET_TIME_Absolute connect_timestamp
Timestamp of the &#39;SESSION_CONNECT&#39; message we sent to the other peer for this address.
void GST_neighbours_notify_data_sent(const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session, size_t size)
Track information about data we transmitted using the given address and session (used to notify ATS a...
const char * transport_name
Name of the transport plugin enabling the communication using this address.
struct GNUNET_ATS_Session * session
Active session for this address.
Asked to initiate connection, trying to get address from ATS.
const char * GST_plugins_a2s(const struct GNUNET_HELLO_Address *address)
Convert a given address to a human-readable format.
struct GNUNET_TRANSPORT_PluginFunctions * GST_plugins_find(const char *name)
Obtain the plugin API based on a plugin name.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
static struct NeighbourMapEntry * lookup_neighbour(const struct GNUNET_PeerIdentity *pid)
Lookup a neighbour entry in the neighbours hash map.
struct GNUNET_HELLO_Address * address
Network-level address information.
Sent SYN message to other peer, waiting for SYN_ACK.
struct GNUNET_PeerIdentity peer
For which peer is this an address?
enum GNUNET_TRANSPORT_PeerState state
The current state of the peer.
static void set_state_and_timeout(struct NeighbourMapEntry *n, enum GNUNET_TRANSPORT_PeerState s, struct GNUNET_TIME_Absolute timeout)
Set net state and state timeout for this neighbour and notify monitoring.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN
Transport SYN message exchanged between transport services to indicate that a session should be marke...
static void free_address(struct NeighbourAddress *na)
We don&#39;t need a given neighbour address any more.
static void unset_primary_address(struct NeighbourMapEntry *n)
Clear the primary address of a neighbour since this address is not valid anymore and notify monitorin...
static void disconnect_neighbour(struct NeighbourMapEntry *n)
Disconnect from the given neighbour, clean up the record.
#define ATS_RESPONSE_TIMEOUT
How long are we willing to wait for a response from ATS before timing out?
#define GNUNET_log(kind,...)
static void send_session_syn_cont(void *cls, const struct GNUNET_PeerIdentity *target, int result, size_t size_payload, size_t size_on_wire)
Continuation called from our attempt to transmitted our GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN to ...
Got our SYN_ACK/ACK, connection is up.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:655
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_session_syn_ack_cont()

static void send_session_syn_ack_cont ( void *  cls,
const struct GNUNET_PeerIdentity target,
int  result,
size_t  size_payload,
size_t  size_on_wire 
)
static

Continuation called from our attempt to transmitted our GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK to the specified target.

Continue processing based on the result. Specifically, if we failed to transmit, discard the address we used.

Parameters
clsNULL
targetwhich peer received the transmission
resultGNUNET_OK if sending worked
size_payloadhow many bytes of payload were sent (ignored)
size_on_wirehow much bandwidth was consumed on the wire (ignored)

Definition at line 2003 of file gnunet-service-transport_neighbours.c.

References _, ACK_SEND_SYN_ACK, NeighbourMapEntry::ack_state, NeighbourAddress::address, ATS_RESPONSE_TIMEOUT, GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_log, GNUNET_OK, GNUNET_TIME_relative_to_absolute(), GNUNET_TRANSPORT_PS_SYN_RECV_ACK, GNUNET_TRANSPORT_PS_SYN_RECV_ATS, GST_plugins_a2s(), lookup_neighbour(), NeighbourMapEntry::primary_address, set_state_and_timeout(), NeighbourMapEntry::state, and unset_primary_address().

Referenced by send_syn_ack_message().

2008 {
2009  struct NeighbourMapEntry *n;
2010 
2011  (void)cls;
2012  (void)size_payload;
2013  (void)size_on_wire;
2014  n = lookup_neighbour(target);
2015  if (NULL == n)
2016  {
2017  /* SYN_ACK continuation was called after neighbor was freed,
2018  * for example due to a time out for the state or the session
2019  * used was already terminated: nothing to do here... */
2020  return;
2021  }
2022 
2024  {
2025  /* SYN_ACK continuation was called after neighbor changed state,
2026  * for example due to a time out for the state or the session
2027  * used was already terminated: nothing to do here... */
2028  return;
2029  }
2030  if (GNUNET_OK == result)
2031  return;
2032 
2034  _("Failed to send SYN_ACK message to peer `%s' using address `%s'\n"),
2035  GNUNET_i2s(target),
2037 
2038  /* Remove address and request and additional one */
2039  /* FIXME: what if the neighbour's primary address
2040  changed in the meantime? Might want to instead
2041  pass "something" around in closure to be sure. */
2047 }
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:246
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Received a SYN, asking ATS about address suggestions.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
struct NeighbourAddress primary_address
Primary address we currently use to communicate with the neighbour.
static int result
Global testing status.
const char * GST_plugins_a2s(const struct GNUNET_HELLO_Address *address)
Convert a given address to a human-readable format.
static struct NeighbourMapEntry * lookup_neighbour(const struct GNUNET_PeerIdentity *pid)
Lookup a neighbour entry in the neighbours hash map.
struct GNUNET_HELLO_Address * address
Network-level address information.
enum GNUNET_TRANSPORT_PeerState state
The current state of the peer.
static void set_state_and_timeout(struct NeighbourMapEntry *n, enum GNUNET_TRANSPORT_PeerState s, struct GNUNET_TIME_Absolute timeout)
Set net state and state timeout for this neighbour and notify monitoring.
static void unset_primary_address(struct NeighbourMapEntry *n)
Clear the primary address of a neighbour since this address is not valid anymore and notify monitorin...
#define ATS_RESPONSE_TIMEOUT
How long are we willing to wait for a response from ATS before timing out?
#define GNUNET_log(kind,...)
enum GST_ACK_State ack_state
When a peer wants to connect we have to reply to the 1st SYN message with a SYN_ACK message...
The neighbour received a SYN message and has to send a SYN_ACK as reply.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
SYN request from other peer was SYN_ACK&#39;ed, waiting for ACK.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_syn_ack_message()

static void send_syn_ack_message ( struct NeighbourAddress na,
struct GNUNET_TIME_Absolute  timestamp 
)
static

Send a SYN_ACK message via the given address.

Parameters
naaddress and session to use
timestamptimestamp to use for the ACK message
Returns
GNUNET_SYSERR if sending immediately failed, GNUNET_OK otherwise

Definition at line 2058 of file gnunet-service-transport_neighbours.c.

References _, ACK_SEND_SYN_ACK, NeighbourMapEntry::ack_state, address, NeighbourAddress::address, ATS_RESPONSE_TIMEOUT, GNUNET_TRANSPORT_PluginFunctions::cls, GNUNET_TRANSPORT_PluginFunctions::get_session, gettext_noop, GNUNET_break, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_i2s(), GNUNET_log, GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_TIME_absolute_hton(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TRANSPORT_PS_SYN_RECV_ATS, GST_ats_new_session(), GST_plugins_a2s(), GST_plugins_find(), GST_stats, TransportSynMessage::header, lookup_neighbour(), GNUNET_HELLO_Address::peer, TransportSynMessage::reserved, GNUNET_TRANSPORT_PluginFunctions::send, send_session_syn_ack_cont(), NeighbourAddress::session, set_state_and_timeout(), GNUNET_MessageHeader::size, TransportSynMessage::timestamp, GNUNET_HELLO_Address::transport_name, GNUNET_MessageHeader::type, and unset_primary_address().

Referenced by GST_neighbours_handle_session_syn(), and switch_address_bl_check_cont().

2060 {
2061  const struct GNUNET_HELLO_Address *address = na->address;
2062  struct GNUNET_ATS_Session *session = na->session;
2063  struct GNUNET_TRANSPORT_PluginFunctions *papi;
2064  struct TransportSynMessage connect_msg;
2065  struct NeighbourMapEntry *n;
2066 
2068  "Sending SYN_ACK to peer `%s'\n",
2069  GNUNET_i2s(&address->peer));
2070 
2071  if (NULL == (papi = GST_plugins_find(address->transport_name)))
2072  {
2073  GNUNET_break(0);
2074  return;
2075  }
2076  if (NULL == session)
2077  session = papi->get_session(papi->cls,
2078  address);
2079  if (NULL == session)
2080  {
2081  GNUNET_break(0);
2082  return;
2083  }
2084  GST_ats_new_session(address,
2085  session);
2087  gettext_noop
2088  ("# SYN_ACK messages sent"),
2089  1, GNUNET_NO);
2090  connect_msg.header.size = htons(sizeof(struct TransportSynMessage));
2091  connect_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK);
2092  connect_msg.reserved = htonl(0);
2093  connect_msg.timestamp = GNUNET_TIME_absolute_hton(timestamp);
2094 
2095  if (GNUNET_SYSERR ==
2096  papi->send(papi->cls,
2097  session,
2098  (const char *)&connect_msg,
2099  sizeof(struct TransportSynMessage),
2100  UINT_MAX,
2102  &send_session_syn_ack_cont, NULL))
2103  {
2105  _("Failed to transmit SYN_ACK message to %s\n"),
2106  GST_plugins_a2s(address));
2107 
2108  n = lookup_neighbour(&address->peer);
2109  if (NULL == n)
2110  {
2111  GNUNET_break(0);
2112  return;
2113  }
2114  /* Remove address and request and additional one */
2120  return;
2121  }
2122 }
GNUNET_TRANSPORT_CreateSession get_session
Function that will be called tell the plugin to create a session object.
GNUNET_TRANSPORT_TransmitFunction send
Function that the transport service will use to transmit data to another peer.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:246
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
#define GNUNET_NO
Definition: gnunet_common.h:78
Received a SYN, asking ATS about address suggestions.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
Message a peer sends to another to indicate that it intends to setup a connection/session for data ex...
static void send_session_syn_ack_cont(void *cls, const struct GNUNET_PeerIdentity *target, int result, size_t size_payload, size_t size_on_wire)
Continuation called from our attempt to transmitted our GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK...
static struct GNUNET_STATISTICS_Handle * GST_stats
Statistics handle.
void * cls
Closure for all of the callbacks.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK
Transport SYN_ACK message exchanged between transport services to indicate that a SYN message was acc...
Information about ongoing sessions of the transport client.
const char * transport_name
Name of the transport plugin enabling the communication using this address.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_ATS_Session * session
Active session for this address.
const char * GST_plugins_a2s(const struct GNUNET_HELLO_Address *address)
Convert a given address to a human-readable format.
struct GNUNET_TRANSPORT_PluginFunctions * GST_plugins_find(const char *name)
Obtain the plugin API based on a plugin name.
static struct NeighbourMapEntry * lookup_neighbour(const struct GNUNET_PeerIdentity *pid)
Lookup a neighbour entry in the neighbours hash map.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_HELLO_Address * address
Network-level address information.
struct GNUNET_PeerIdentity peer
For which peer is this an address?
static void set_state_and_timeout(struct NeighbourMapEntry *n, enum GNUNET_TRANSPORT_PeerState s, struct GNUNET_TIME_Absolute timeout)
Set net state and state timeout for this neighbour and notify monitoring.
An address for communicating with a peer.
static void unset_primary_address(struct NeighbourMapEntry *n)
Clear the primary address of a neighbour since this address is not valid anymore and notify monitorin...
#define ATS_RESPONSE_TIMEOUT
How long are we willing to wait for a response from ATS before timing out?
#define GNUNET_log(kind,...)
enum GST_ACK_State ack_state
When a peer wants to connect we have to reply to the 1st SYN message with a SYN_ACK message...
The neighbour received a SYN message and has to send a SYN_ACK as reply.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:655
static char * address
GNS address for this phone.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
void GST_ats_new_session(const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session)
Notify ATS about a new session now existing for the given address.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ inbound_bw_tracker_update()

static void inbound_bw_tracker_update ( void *  cls)
static

Function called by the bandwidth tracker for a peer whenever the tracker's state changed such that we need to recalculate the delay for flow control.

We calculate the latest delay and inform the plugin (if applicable).

Parameters
clsthe struct NeighbourMapEntry to update calculations for

Definition at line 2134 of file gnunet-service-transport_neighbours.c.

References NeighbourAddress::address, GNUNET_TRANSPORT_PluginFunctions::cls, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GST_neighbours_calculate_receive_delay(), GST_plugins_find(), NeighbourMapEntry::id, NeighbourMapEntry::primary_address, GNUNET_TIME_Relative::rel_value_us, NeighbourAddress::session, GNUNET_HELLO_Address::transport_name, and GNUNET_TRANSPORT_PluginFunctions::update_inbound_delay.

Referenced by setup_neighbour().

2135 {
2136  struct NeighbourMapEntry *n = cls;
2137  struct GNUNET_TRANSPORT_PluginFunctions *papi;
2138  struct GNUNET_TIME_Relative delay;
2139  int do_forward;
2140 
2141  if (NULL == n->primary_address.address)
2142  return; /* not active, ignore */
2144  GNUNET_assert(NULL != papi);
2145  if (NULL == papi->update_inbound_delay)
2146  return;
2148  0,
2149  &do_forward);
2151  "New inbound delay for peer `%s' is %llu ms\n",
2152  GNUNET_i2s(&n->id),
2153  (unsigned long long)delay.rel_value_us / 1000LL);
2154  if (NULL == n->primary_address.session)
2155  return;
2156  papi->update_inbound_delay(papi->cls,
2157  &n->id,
2159  delay);
2160 }
uint64_t rel_value_us
The actual value.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
struct GNUNET_TIME_Relative GST_neighbours_calculate_receive_delay(const struct GNUNET_PeerIdentity *sender, ssize_t size, int *do_forward)
We have received a message from the given sender.
void * cls
Closure for all of the callbacks.
struct NeighbourAddress primary_address
Primary address we currently use to communicate with the neighbour.
const char * transport_name
Name of the transport plugin enabling the communication using this address.
struct GNUNET_PeerIdentity id
Identity of this neighbour.
struct GNUNET_ATS_Session * session
Active session for this address.
GNUNET_TRANSPORT_UpdateInboundDelay update_inbound_delay
Function that will be called whenever the transport service wants to notify the plugin that the inbou...
struct GNUNET_TRANSPORT_PluginFunctions * GST_plugins_find(const char *name)
Obtain the plugin API based on a plugin name.
struct GNUNET_HELLO_Address * address
Network-level address information.
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
#define GNUNET_log(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_neighbour()

static struct NeighbourMapEntry* setup_neighbour ( const struct GNUNET_PeerIdentity peer)
static

Create a fresh entry in the neighbour map for the given peer.

Parameters
peerpeer to create an entry for
Returns
new neighbour map entry

Definition at line 2170 of file gnunet-service-transport_neighbours.c.

References NeighbourMapEntry::ack_state, ACK_UNDEFINED, GNUNET_assert, GNUNET_ATS_connectivity_suggest(), GNUNET_BANDWIDTH_tracker_init(), GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_put(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_new, GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_TIME_absolute_get(), GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TRANSPORT_PS_NOT_CONNECTED, GST_ats_connect, GST_my_identity, NeighbourMapEntry::id, NeighbourMapEntry::in_tracker, inbound_bw_tracker_update(), NeighbourMapEntry::last_util_transmission, master_task(), MAX_BANDWIDTH_CARRY_S, NeighbourMapEntry::neighbour_receive_quota, peer, set_state_and_timeout(), NeighbourMapEntry::suggest_handle, and NeighbourMapEntry::task.

Referenced by GST_neighbours_handle_session_syn(), and switch_address_bl_check_cont().

2171 {
2172  struct NeighbourMapEntry *n;
2173 
2174  if (0 ==
2175  memcmp(&GST_my_identity,
2176  peer,
2177  sizeof(struct GNUNET_PeerIdentity)))
2178  {
2180  "Cowardly refusing to consider myself my neighbour!\n");
2181  return NULL;
2182  }
2184  "Creating new neighbour entry for `%s'\n",
2185  GNUNET_i2s(peer));
2186  n = GNUNET_new(struct NeighbourMapEntry);
2187  n->id = *peer;
2188  n->ack_state = ACK_UNDEFINED;
2193  n,
2202  &n->id,
2203  n,
2206  peer,
2207  0);
2208 
2209  return n;
2210 }
static struct GNUNET_PeerIdentity GST_my_identity
Our public key.
static struct GNUNET_CONTAINER_MultiPeerMap * neighbours
Hash map from peer identities to the respective struct NeighbourMapEntry.
void GNUNET_BANDWIDTH_tracker_init(struct GNUNET_BANDWIDTH_Tracker *av, GNUNET_BANDWIDTH_TrackerUpdateCallback update_cb, void *update_cb_cls, struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit, uint32_t max_carry_s)
Initialize bandwidth tracker.
Definition: bandwidth.c:302
We did not receive a SYN message for this neighbour.
struct GNUNET_BANDWIDTH_Tracker in_tracker
Tracker for inbound bandwidth.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT
Bandwidth (in/out) to assume initially (before either peer has communicated any particular preference...
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
struct GNUNET_ATS_ConnectivitySuggestHandle * GNUNET_ATS_connectivity_suggest(struct GNUNET_ATS_ConnectivityHandle *ch, const struct GNUNET_PeerIdentity *peer, uint32_t strength)
We would like to receive address suggestions for a peer.
Fresh peer or completely disconnected.
struct GNUNET_ATS_ConnectivitySuggestHandle * suggest_handle
ATS address suggest handle.
static void inbound_bw_tracker_update(void *cls)
Function called by the bandwidth tracker for a peer whenever the tracker&#39;s state changed such that we...
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1264
struct GNUNET_PeerIdentity id
Identity of this neighbour.
struct GNUNET_SCHEDULER_Task * task
Main task that drives this peer (timeouts, keepalives, etc.).
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
#define MAX_BANDWIDTH_CARRY_S
Number of seconds that available bandwidth carries over (can accumulate).
There must only be one value per key; storing a value should fail if a value under the same key alrea...
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
static void set_state_and_timeout(struct NeighbourMapEntry *n, enum GNUNET_TRANSPORT_PeerState s, struct GNUNET_TIME_Absolute timeout)
Set net state and state timeout for this neighbour and notify monitoring.
struct GNUNET_ATS_ConnectivityHandle * GST_ats_connect
ATS connectivity handle.
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.
The identity of the host (wraps the signing key of the peer).
#define GNUNET_log(kind,...)
enum GST_ACK_State ack_state
When a peer wants to connect we have to reply to the 1st SYN message with a SYN_ACK message...
struct GNUNET_BANDWIDTH_Value32NBO neighbour_receive_quota
Latest quota the other peer send us in bytes per second.
static void master_task(void *cls)
Master task run for every neighbour.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
struct GNUNET_TIME_Absolute last_util_transmission
Date of last utilization transmission.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GST_neighbours_handle_session_syn()

int GST_neighbours_handle_session_syn ( const struct GNUNET_MessageHeader message,
const struct GNUNET_PeerIdentity peer 
)

We received a 'SYN' message from the other peer.

We received a 'SESSION_CONNECT' message from the other peer.

Consider switching to it.

Parameters
messagepossibly a struct TransportSynMessage (check format)
peeridentity of the peer to switch the address for
Returns
GNUNET_OK if the message was fine, GNUNET_SYSERR on serious error

Definition at line 2253 of file gnunet-service-transport_neighbours.c.

References _, ACK_SEND_ACK, ACK_SEND_SYN_ACK, NeighbourMapEntry::ack_state, NeighbourAddress::address, ATS_RESPONSE_TIMEOUT, NeighbourMapEntry::connect_ack_timestamp, free_neighbour(), gettext_noop, GNUNET_assert, GNUNET_break, GNUNET_break_op, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_relative_to_absolute(), GNUNET_TRANSPORT_ps2s(), GNUNET_TRANSPORT_PS_CONNECTED, GNUNET_TRANSPORT_PS_DISCONNECT, GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED, GNUNET_TRANSPORT_PS_INIT_ATS, GNUNET_TRANSPORT_PS_NOT_CONNECTED, GNUNET_TRANSPORT_PS_RECONNECT_ATS, GNUNET_TRANSPORT_PS_RECONNECT_SENT, GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT, GNUNET_TRANSPORT_PS_SYN_RECV_ACK, GNUNET_TRANSPORT_PS_SYN_RECV_ATS, GNUNET_TRANSPORT_PS_SYN_SENT, GST_my_identity, GST_stats, lookup_neighbour(), NeighbourMapEntry::primary_address, print_ack_state(), TransportSynMessage::reserved, send_syn_ack_message(), NeighbourAddress::session, set_state_and_timeout(), setup_neighbour(), GNUNET_MessageHeader::size, NeighbourMapEntry::state, and TransportSynMessage::timestamp.

Referenced by connect_bl_check_cont().

2255 {
2256  const struct TransportSynMessage *scm;
2257  struct NeighbourMapEntry *n;
2258  struct GNUNET_TIME_Absolute ts;
2259 
2260  if (ntohs(message->size) != sizeof(struct TransportSynMessage))
2261  {
2262  GNUNET_break_op(0);
2263  return GNUNET_SYSERR;
2264  }
2266  gettext_noop
2267  ("# SYN messages received"),
2268  1, GNUNET_NO);
2269  if (NULL == neighbours)
2270  {
2272  _("SYN request from peer `%s' ignored due impending shutdown\n"),
2273  GNUNET_i2s(peer));
2274  return GNUNET_OK; /* we're shutting down */
2275  }
2276  scm = (const struct TransportSynMessage *)message;
2277  GNUNET_break_op(0 == ntohl(scm->reserved));
2279  if (0 ==
2280  memcmp(&GST_my_identity,
2281  peer,
2282  sizeof(struct GNUNET_PeerIdentity)))
2283  {
2284  /* loopback connection-to-self, ignore */
2285  return GNUNET_SYSERR;
2286  }
2287  n = lookup_neighbour(peer);
2288  if (NULL == n)
2289  {
2290  /* This is a new neighbour and set to not connected */
2291  n = setup_neighbour(peer);
2292  GNUNET_assert(NULL != n);
2293  }
2294 
2295  /* Remember this SYN message in neighbour */
2297  n->connect_ack_timestamp = ts;
2298 
2300  "Received SYN for peer `%s' in state %s/%s\n",
2301  GNUNET_i2s(peer),
2304 
2305  switch (n->state)
2306  {
2308  /* Request an address from ATS to send SYN_ACK to this peer */
2312  break;
2313 
2315  /* SYN message takes priority over us asking ATS for address:
2316  * Wait for ATS to suggest an address and send SYN_ACK */
2320  break;
2321 
2323  /* We already wait for an address to send an SYN_ACK */
2324  break;
2325 
2328  /* Send ACK immediately */
2329  n->ack_state = ACK_SEND_ACK;
2331  ts);
2332  break;
2333 
2335  /* we are already connected and can thus send the ACK immediately */
2338  n->ack_state = ACK_SEND_ACK;
2340  ts);
2341  break;
2342 
2344  /* We wait for ATS address suggestion */
2345  break;
2346 
2348  /* We received a SYN message while waiting for a SYN_ACK in fast
2349  * reconnect. Send SYN_ACK immediately */
2350  n->ack_state = ACK_SEND_ACK;
2353  break;
2354 
2356  /* We are already connected and can thus send the ACK immediately;
2357  still, it can never hurt to have an alternative address, so also
2358  tell ATS about it */
2361  n->ack_state = ACK_SEND_ACK;
2363  ts);
2364  break;
2365 
2367  /* Get rid of remains and re-try */
2368  free_neighbour(n);
2369  n = setup_neighbour(peer);
2370  GNUNET_assert(NULL != n);
2371  /* Remember the SYN time stamp for ACK message */
2373  n->connect_ack_timestamp = ts;
2374  /* Request an address for the peer */
2378  break;
2379 
2381  /* should not be possible */
2382  GNUNET_assert(0);
2383  break;
2384 
2385  default:
2387  "Unhandled state `%s'\n",
2389  GNUNET_break(0);
2390  return GNUNET_SYSERR;
2391  }
2392  return GNUNET_OK;
2393 }
static struct GNUNET_PeerIdentity GST_my_identity
Our public key.
static struct GNUNET_CONTAINER_MultiPeerMap * neighbours
Hash map from peer identities to the respective struct NeighbourMapEntry.
Connection got into trouble, rest of the system still believes it to be up, but we&#39;re getting a new a...
We have some primary connection, but ATS suggested we switch to some alternative; we now sent a SYN m...
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:671
Sent SYN over new address (either by ATS telling us to switch addresses or from RECONNECT_ATS); if th...
We&#39;re finished with the disconnect; and are cleaning up the state now! We put the struct into this st...
struct GNUNET_TIME_AbsoluteNBO timestamp
Absolute time at the sender.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:246
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_TIME_Absolute connect_ack_timestamp
Timestamp we should include in our next SYN_ACK message.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Received a SYN, asking ATS about address suggestions.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static char * print_ack_state(enum GST_ACK_State s)
Convert the given ACK state to a string.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
Message a peer sends to another to indicate that it intends to setup a connection/session for data ex...
static void free_neighbour(struct NeighbourMapEntry *n)
Free a neighbour map entry.
Fresh peer or completely disconnected.
static struct GNUNET_STATISTICS_Handle * GST_stats
Statistics handle.
struct NeighbourAddress primary_address
Primary address we currently use to communicate with the neighbour.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
struct GNUNET_ATS_Session * session
Active session for this address.
Asked to initiate connection, trying to get address from ATS.
static struct NeighbourMapEntry * lookup_neighbour(const struct GNUNET_PeerIdentity *pid)
Lookup a neighbour entry in the neighbours hash map.
const char * GNUNET_TRANSPORT_ps2s(enum GNUNET_TRANSPORT_PeerState state)
Convert a transport state to a human readable string.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_HELLO_Address * address
Network-level address information.
Sent SYN message to other peer, waiting for SYN_ACK.
enum GNUNET_TRANSPORT_PeerState state
The current state of the peer.
static void set_state_and_timeout(struct NeighbourMapEntry *n, enum GNUNET_TRANSPORT_PeerState s, struct GNUNET_TIME_Absolute timeout)
Set net state and state timeout for this neighbour and notify monitoring.
The neighbour sent a SYN_ACK message and has to send a ACK as reply.
The identity of the host (wraps the signing key of the peer).
static void send_syn_ack_message(struct NeighbourAddress *na, struct GNUNET_TIME_Absolute timestamp)
Send a SYN_ACK message via the given address.
Disconnect in progress (we&#39;re sending the DISCONNECT message to the other peer; after that is finishe...
#define ATS_RESPONSE_TIMEOUT
How long are we willing to wait for a response from ATS before timing out?
#define GNUNET_log(kind,...)
enum GST_ACK_State ack_state
When a peer wants to connect we have to reply to the 1st SYN message with a SYN_ACK message...
static struct NeighbourMapEntry * setup_neighbour(const struct GNUNET_PeerIdentity *peer)
Create a fresh entry in the neighbour map for the given peer.
Time for absolute times used by GNUnet, in microseconds.
The neighbour received a SYN message and has to send a SYN_ACK as reply.
Got our SYN_ACK/ACK, connection is up.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
SYN request from other peer was SYN_ACK&#39;ed, waiting for ACK.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ try_run_fast_ats_update()

static int try_run_fast_ats_update ( const struct GNUNET_HELLO_Address address,
struct GNUNET_ATS_Session session,
struct GNUNET_BANDWIDTH_Value32NBO  bandwidth_in,
struct GNUNET_BANDWIDTH_Value32NBO  bandwidth_out 
)
static

Check if the given address is the same that we are already using for the respective neighbour.

If so, update the bandwidth assignment and possibly the session and return GNUNET_OK. If the new address is different from what the neighbour is using right now, return GNUNET_NO.

Parameters
addressaddress of the other peer,
sessionsession to use or NULL if transport should initiate a session
bandwidth_ininbound quota to be used when connection is up, 0 to disconnect from peer
bandwidth_outoutbound quota to be used when connection is up, 0 to disconnect from peer
Returns
GNUNET_OK if we were able to just update the bandwidth and session, GNUNET_NO if more extensive changes are required (address changed)

Definition at line 2413 of file gnunet-service-transport_neighbours.c.

References NeighbourAddress::address, NeighbourAddress::bandwidth_in, NeighbourAddress::bandwidth_out, GNUNET_assert, GNUNET_HELLO_address_cmp(), GNUNET_NO, GNUNET_OK, GNUNET_YES, GST_ats_is_known(), lookup_neighbour()