30#include "../../service/cadet/cadet.h"
32#define STREAM_BUFFER_SIZE 1024
294 "read() returned %s\n",
300 "Read %u bytes from stdio\n",
388 "Incoming connection from %s\n",
448 size_t payload_size = ntohs (message->
size) -
sizeof(*message);
483 len = ntohs (message->
size) -
sizeof(*message);
485 buf = (
const char *) &message[1];
489 done = write (1, &buf[off], len - off);
521 "%s tunnel: %c, paths: %u\n",
544 fprintf (stdout,
"Path of length %u: ", ppd->
path_length);
545 for (
unsigned int i = 0; i < ppd->
path_length; i++)
549 fprintf (stdout,
"\n");
569 "%s [ENC: %s, CON: %s] CHs: %u, CONNs: %u\n",
606 fprintf (stderr,
_ (
"Invalid peer ID `%s'\n"),
peer_id);
685 _ (
"Extra arguments are not applicable "
686 "in combination with this option.\n"));
746 _ (
"Invalid target `%s'\n"),
752 "Connecting to `%s:%s'\n",
773 if ((NULL ==
lp) && (NULL ==
job) && (NULL ==
ch))
790main (
int argc,
char *
const *argv)
793 const char helpstr[] =
794 "Create tunnels and retrieve info about CADET's status.";
800 gettext_noop (
"Provide information about a particular connection"),
811 "Listen for connections using a shared secret among sender and recipient"),
817 "Provide information about a patricular peer"),
822 "Provide information about all peers"),
827 "Provide information about all tunnels"),
835 "gnunet-cadet (OPTIONS | PEER_ID SHARED_SECRET)",
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
struct GNUNET_GETOPT_CommandLineOption options[]
struct GNUNET_MQ_MessageHandlers handlers[]
struct GNUNET_MessageHeader * msg
struct GNUNET_MQ_Envelope * env
#define gettext_noop(String)
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static void peers_callback(void *cls, const struct GNUNET_CADET_PeerListEntry *ple)
Method called to retrieve information about all peers in CADET, called once per peer.
static struct GNUNET_HashCode porthash
HashCode of the given port string.
#define STREAM_BUFFER_SIZE
static struct GNUNET_SCHEDULER_Task * echo_task
Task for next echo request.
static void listen_stdio(void)
Wait for input on STDIO and send it out over the ch.
static int check_data(void *cls, const struct GNUNET_MessageHeader *message)
Check data message sanity.
static char * channel_id
Option –channel.
static const char * conn_2s(uint16_t status)
Convert connection status to human readable string.
static struct GNUNET_SCHEDULER_Task * job
Task for main job.
static char * listen_port
Port to listen on (-o).
static void path_callback(void *cls, const struct GNUNET_CADET_PeerPathDetail *ppd)
Method called to retrieve information about paths to a specific peer known to the service.
struct GNUNET_CADET_Port * lp
Data structure for ongoing reception of incoming virtual circuits.
static void get_peers(void *cls)
Call CADET's meta API, get all peers known to a peer.
static struct GNUNET_SCHEDULER_Task * rd_task
Task for reading from stdin.
static void show_connection(void *cls)
Call CADET's monitor API, get info of one connection.
static struct GNUNET_CADET_ListTunnels * tio
Active tunnel listing operation.
static void channel_ended(void *cls, const struct GNUNET_CADET_Channel *channel)
Function called whenever a channel is destroyed.
static void read_stdio(void *cls)
Task run in stdio mode, after some data is available at stdin.
static const struct GNUNET_CONFIGURATION_Handle * my_cfg
Our configuration.
static struct GNUNET_TIME_Absolute echo_time
Time of last echo request.
static char * peer_id
Option –peer.
static struct GNUNET_CADET_GetPath * gpo
Active get path operation.
static struct GNUNET_CADET_Channel * ch
Channel handle.
static void shutdown_task(void *cls)
Task to shut down this application.
static void mq_cb(void *cls)
static int request_peers
Option -P.
static void * channel_incoming(void *cls, struct GNUNET_CADET_Channel *channel, const struct GNUNET_PeerIdentity *initiator)
Method called whenever another peer has added us to a channel the other peer initiated.
static void get_tunnels(void *cls)
Call CADET's meta API, get all tunnels known to a peer.
static char * target_id
Peer to connect to.
static char * conn_id
Option –connection.
static void show_peer(void *cls)
Call CADET's monitor API, get info of one peer.
static void tunnels_callback(void *cls, const struct GNUNET_CADET_TunnelDetails *td)
Method called to retrieve information about all tunnels in CADET.
static const char * target_port
Port to connect to.
static int request_tunnels
Option -T.
static void show_channel(void *cls)
Call CADET's monitor API, get info of one channel.
static int echo
Request echo service.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run by the scheduler.
static void handle_data(void *cls, const struct GNUNET_MessageHeader *message)
Function called whenever a message is received.
int main(int argc, char *const *argv)
The main function to obtain peer information.
static void send_echo(void *cls)
Send an echo request to the remote peer.
static const char * enc_2s(uint16_t status)
Convert encryption status to human readable string.
static struct GNUNET_CADET_Handle * mh
Cadet handle.
static unsigned int sent_pkt
static struct GNUNET_CADET_PeersLister * plo
Active peer listing operation.
static char * data
The data to insert into the dht.
static char * res
Currently read line or NULL on EOF.
static size_t data_size
Number of bytes in data.
static int status
The program status; 0 for success.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
CADET service; establish channels to distant peers.
struct GNUNET_CADET_Handle * GNUNET_CADET_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the MQ-based cadet service.
void GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel)
Indicate readiness to receive the next message on a channel.
struct GNUNET_CADET_PeersLister * GNUNET_CADET_list_peers(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CADET_PeersCB callback, void *callback_cls)
Request information about peers known to the running cadet service.
void GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel)
Destroy an existing channel.
struct GNUNET_CADET_ListTunnels * GNUNET_CADET_list_tunnels(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CADET_TunnelsCB callback, void *callback_cls)
Request information about tunnels of the running cadet peer.
struct GNUNET_MQ_Handle * GNUNET_CADET_get_mq(const struct GNUNET_CADET_Channel *channel)
Obtain the message queue for a connected channel.
struct GNUNET_CADET_Port * GNUNET_CADET_open_port(struct GNUNET_CADET_Handle *h, const struct GNUNET_HashCode *port, GNUNET_CADET_ConnectEventHandler connects, void *connects_cls, GNUNET_CADET_WindowSizeEventHandler window_changes, GNUNET_CADET_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers)
Open a port to receive incoming MQ-based channels.
void * GNUNET_CADET_list_tunnels_cancel(struct GNUNET_CADET_ListTunnels *lt)
Cancel a monitor request.
void GNUNET_CADET_disconnect(struct GNUNET_CADET_Handle *handle)
Disconnect from the cadet service.
void GNUNET_CADET_close_port(struct GNUNET_CADET_Port *p)
Close a port opened with GNUNET_CADET_open_port.
struct GNUNET_CADET_Channel * GNUNET_CADET_channel_create(struct GNUNET_CADET_Handle *h, void *channel_cls, const struct GNUNET_PeerIdentity *destination, const struct GNUNET_HashCode *port, GNUNET_CADET_WindowSizeEventHandler window_changes, GNUNET_CADET_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers)
Create a new channel towards a remote peer.
void * GNUNET_CADET_get_path_cancel(struct GNUNET_CADET_GetPath *gp)
Cancel gp operation.
void * GNUNET_CADET_list_peers_cancel(struct GNUNET_CADET_PeersLister *pl)
Cancel a peer info request.
struct GNUNET_CADET_GetPath * GNUNET_CADET_get_path(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_PeerIdentity *id, GNUNET_CADET_PathCB callback, void *callback_cls)
Request information about a peer known to the running cadet peer.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
#define GNUNET_log(kind,...)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a string representing a public key to a public key.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_SCHEDULER_PRIORITY_DEFAULT
Run with the default priority (normal P2P operations).
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_MESSAGE
@ GNUNET_ERROR_TYPE_DEBUG
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore.
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
void GNUNET_NETWORK_fdset_set_native(struct GNUNET_NETWORK_FDSet *to, int nfd)
Set a native fd in a set.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
#define GNUNET_MESSAGE_TYPE_CADET_CLI
Traffic (net-cat style) used by the Command Line Interface.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_select(enum GNUNET_SCHEDULER_Priority prio, struct GNUNET_TIME_Relative delay, const struct GNUNET_NETWORK_FDSet *rs, const struct GNUNET_NETWORK_FDSet *ws, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when any of the specified file descriptor set...
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
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.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
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...
#define GNUNET_TIME_UNIT_SECONDS
One second.
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
Opaque handle to a channel.
Opaque handle to the service.
Information we return per peer.
unsigned int n_paths
Number of disjoint known paths to peer.
struct GNUNET_PeerIdentity peer
Which peer is the information about?
int have_tunnel
Do we have a tunnel to this peer?
Detailed information we return per peer.
unsigned int path_length
Number of entries on the path.
const struct GNUNET_PeerIdentity * path
Array of PEER_IDs representing all paths to reach the peer.
unsigned int target_offset
Offset of the target peer on the path.
Details about a tunnel managed by CADET.
uint16_t cstate
What is our connectivity state?
uint32_t channels
How many channels use the tunnel.
uint16_t estate
What is our encryption state?
struct GNUNET_PeerIdentity peer
Target of the tunnel.
uint32_t connections
How many connections support the tunnel.
Definition of a command line option.
Message handler for a specific message type.
collection of IO descriptors
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Entry in list of pending tasks.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.