agent.h 2.03 KB
Newer Older
Dafydd Harries's avatar
Dafydd Harries committed
1 2 3 4

#ifndef _AGENT_H
#define _AGENT_H

5
#include <arpa/inet.h>
6

7 8 9
#include <glib.h>

#include "udp.h"
10 11 12
#include "address.h"


Dafydd Harries's avatar
Dafydd Harries committed
13 14
/*** candidate ***/

Dafydd Harries's avatar
Dafydd Harries committed
15
typedef enum candidate_type CandidateType;
Dafydd Harries's avatar
Dafydd Harries committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29

enum candidate_type
{
  CANDIDATE_TYPE_HOST,
  CANDIDATE_TYPE_SERVER_REFLEXIVE,
  CANDIDATE_TYPE_PEER_REFLEXIVE,
  CANDIDATE_TYPE_RELAYED,
};


typedef struct _candidate Candidate;

struct _candidate
{
Dafydd Harries's avatar
Dafydd Harries committed
30
  CandidateType type;
Dafydd Harries's avatar
Dafydd Harries committed
31
  guint id;
32 33
  Address addr;
  Address base_addr;
Dafydd Harries's avatar
Dafydd Harries committed
34 35
  guint16 port;
  guint32 priority;
36 37
  guint stream_id;
  guint component_id;
Dafydd Harries's avatar
Dafydd Harries committed
38 39
  // guint generation;
  // gchar *foundation;
40
  UDPSocket sock;
Dafydd Harries's avatar
Dafydd Harries committed
41 42 43
};


44 45 46 47
Candidate *
candidate_new (CandidateType type);
void
candidate_free (Candidate *candidate);
48 49 50 51
gfloat
candidate_jingle_priority (Candidate *candidate);
guint32
candidate_ice_priority (Candidate *candidate);
52 53


Dafydd Harries's avatar
Dafydd Harries committed
54 55 56
/*** event ***/


Dafydd Harries's avatar
Dafydd Harries committed
57 58
typedef enum event_type EventType;

Dafydd Harries's avatar
Dafydd Harries committed
59 60 61 62 63 64 65 66 67 68
enum event_type
{
  EVENT_CANDIDATE_SELECTED,
};


typedef struct _event Event;

struct _event
{
Dafydd Harries's avatar
Dafydd Harries committed
69
  EventType type;
Dafydd Harries's avatar
Dafydd Harries committed
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

  union {
    struct {
      Address *addr;
      guint candidate_id;
    } request_port;
    struct {
      Address *from;
      guint from_port;
      Address *to;
      guint to_port;
    } request_stun_query;
  };
};


void
event_free (Event *ev);


/*** agent ***/


typedef struct _agent Agent;

struct _agent
{
  guint next_candidate_id;
Dafydd Harries's avatar
Dafydd Harries committed
98
  guint next_stream_id;
99
  UDPSocketManager *sockmgr;
Dafydd Harries's avatar
Dafydd Harries committed
100 101
  GSList *local_addresses;
  GSList *local_candidates;
102
  GSList *remote_candidates;
Dafydd Harries's avatar
Dafydd Harries committed
103 104 105 106 107
  GSList *streams;
  GSList *events;
};


108 109 110 111
typedef void (*AgentRecvHandler) (
  Agent *agent, guint stream_id, guint component_id, guint len, gchar *buf);


Dafydd Harries's avatar
Dafydd Harries committed
112
Agent *
113
ice_agent_new (UDPSocketManager *mgr);
Dafydd Harries's avatar
Dafydd Harries committed
114 115 116 117
Event *
ice_agent_pop_event (Agent *agent);
void
ice_agent_add_local_address (Agent *agent, Address *addr);
Dafydd Harries's avatar
Dafydd Harries committed
118
guint
119 120
ice_agent_add_stream (
  Agent *agent,
121
  AgentRecvHandler handle_recv);
Dafydd Harries's avatar
Dafydd Harries committed
122 123
void
ice_agent_free (Agent *agent);
124 125 126 127 128 129
void
ice_agent_add_remote_candidate (
  Agent *agent,
  CandidateType type,
  Address *addr,
  guint port);
Dafydd Harries's avatar
Dafydd Harries committed
130 131 132 133
void
ice_agent_recv (
  Agent *agent,
  guint candidate_id);
Dafydd Harries's avatar
Dafydd Harries committed
134 135 136

#endif /* _AGENT_H */