78 lines
2.2 KiB
C
78 lines
2.2 KiB
C
#pragma once
|
|
|
|
#include <assert.h>
|
|
#include <stdint.h>
|
|
#include <time.h>
|
|
#include <netinet/in.h>
|
|
|
|
#include "timer.h"
|
|
#include "link.h"
|
|
|
|
#define EVENT_TYPE__INVALID 0x00000000
|
|
#define EVENT_TYPE__TIME_START 0x12858517
|
|
#define EVENT_TYPE__TIME_RESUME 0x56100f0f
|
|
#define EVENT_TYPE__TIME_STOP 0xdf75d3f8
|
|
#define EVENT_TYPE__AVERAGE_RTT 0xc7065931
|
|
#define EVENT_TYPE__PING 0x0ba0d4c2
|
|
#define EVENT_TYPE__PONG 0x49a87c9d
|
|
#define EVENT_TYPE__ACK 0xfde7959f
|
|
|
|
static_assert((sizeof (struct timespec)) == 8 + 8);
|
|
|
|
struct event {
|
|
uint32_t type;
|
|
uint32_t sequence;
|
|
};
|
|
|
|
struct packet_stopwatch {
|
|
struct event event;
|
|
struct stopwatch_time stopwatch_time;
|
|
};
|
|
|
|
static_assert((sizeof (struct packet_stopwatch)) ==
|
|
(sizeof (struct event)) + (sizeof (struct stopwatch_time)));
|
|
|
|
struct packet_start {
|
|
struct event event;
|
|
};
|
|
|
|
static_assert((sizeof (struct packet_start)) == (sizeof (struct event)));
|
|
|
|
struct packet_ack {
|
|
struct event event;
|
|
};
|
|
|
|
static_assert((sizeof (struct packet_ack)) == (sizeof (struct event)));
|
|
|
|
struct packet_rtt_delay {
|
|
struct event event;
|
|
struct timespec offset;
|
|
};
|
|
|
|
static_assert((sizeof (struct packet_rtt_delay)) == (sizeof (struct event)) + (sizeof (struct timespec)));
|
|
|
|
struct packet_ping_pong {
|
|
struct event event;
|
|
struct timespec time;
|
|
};
|
|
|
|
int packet_send_ping(int sockfd,
|
|
struct sockaddr_in6 * dest_addr);
|
|
int packet_send_pong(int sockfd,
|
|
struct sockaddr_in6 * dest_addr,
|
|
struct timespec * time);
|
|
int packet_send_average_rtt(int sockfd,
|
|
struct sockaddr_in6 * dest_addr,
|
|
struct timespec * time);
|
|
|
|
int packet_send_start_event(int sockfd,
|
|
struct sockaddr_in6 * dest_addr,
|
|
struct link_state * link_state);
|
|
int packet_send_resume_event(int sockfd,
|
|
struct sockaddr_in6 * dest_addr,
|
|
struct link_state * link_state);
|
|
int packet_send_stopwatch_event(int sockfd,
|
|
struct sockaddr_in6 * dest_addr,
|
|
struct timer_state * timer_state,
|
|
struct link_state * link_state);
|