-
Notifications
You must be signed in to change notification settings - Fork 16
/
i2psam-c.h
200 lines (168 loc) · 5.14 KB
/
i2psam-c.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/**
* C wrapper for i2psam
* Author: jeff
* License: MIT
* probably contains bugs :-DDDD
*/
#ifndef I2PSAM_C_H
#define I2PSAM_C_H
#include <stdint.h>
#include <stdlib.h>
struct i2psam_destination;
struct i2psam_stream_session;
struct i2psam_socket;
struct i2psam_stream_settings
{
/**
* hostname of sam interface
*/
const char *samhost;
/**
* port of sam interface
*/
const uint16_t samport;
/**
* nickname for sam session
*/
const char *nickname;
/**
* i2cp options string
*/
const char *i2cp_opts;
/**
* destination private key
*/
const char *destination;
};
/**
* create new stream session
*/
struct i2psam_stream_session *i2psam_stream_session_new(struct i2psam_stream_settings *);
/**
* close and free stream session
*/
void i2psam_stream_session_free(struct i2psam_stream_session *);
/**
* get sam host of stream session
* @return must be free()'d by caller
*/
const char *i2psam_get_samhost(struct i2psam_stream_session *);
/**
* get sam port of stream session
*/
uint16_t i2psam_get_samport(struct i2psam_stream_session *);
/**
* get sam session's nickname
* @return must be free()'d by caller
*/
const char *i2psam_get_nickname(struct i2psam_stream_session *);
/**
* get sam session's id
* @return must be free()'d by caller
*/
const char *i2psam_get_session_id(struct i2psam_stream_session *);
/**
* get min version from sam session's handshake
* @return must be free()'d by caller
*/
const char *i2psam_get_sam_min_version(struct i2psam_stream_session *);
/**
* get max version from sam session's handshake
* @return must be free()'d by caller
*/
const char *i2psam_get_sam_max_version(struct i2psam_stream_session *);
/**
* get current version in use with sam session
* @return must be free()'d by caller
*/
const char *i2psam_get_sam_version(struct i2psam_stream_session *);
/**
* get i2cp options used by sam session
* @return must be free()'d by caller
*/
const char *i2psam_get_i2cp_options(struct i2psam_stream_session *);
/**
* return 1 if session is sick otherwise returns 0
*/
int i2psam_is_sick(struct i2psam_stream_session *);
/**
* accept a new inbound connection
* @param silent 0 if we want to obtain the remote's destination, nonzero means don't
*/
struct i2psam_socket *i2psam_accept(struct i2psam_stream_session *, int silent);
/**
* connect to remote destination
* @param destination full public destination base64 blob
* @param silent 0 if we want to get verbose error info from connect, nonzero means don't
*/
struct i2psam_socket *i2psam_connect(struct i2psam_stream_session *, const char *destination, int silent);
/**
* forward all inbound connections to a remote endpoint
* @param host remote hostname of endpoint
* @param port remote port of endpoint
* @param silent 0 if we want to be verbose when forwarding to remote endpoint, nonzero means don't
* @return -1 on fail, otherwise 0
*/
int i2psam_forward(struct i2psam_stream_session *, const char *host, uint16_t port, int silent);
/**
* do a name lookup, if return is non null caller must free()'d
* @param name the name to resolve
* @return public destination base64 blob for the name or NULL if the name lookup fails
*/
const char *i2psam_namelookup(struct i2psam_stream_session *, const char *name);
/**
* generate a new i2p destination keypair, return value must be free()'d when done
* @return newly generated keypair
*/
struct i2psam_destination *i2psam_dest_generate(struct i2psam_stream_session *);
/**
* stop forwarding to remote endpoint
* @param host hostname of remote endpoint
* @param port port of remote endpoint
*/
void i2psam_stop_forwarding(struct i2psam_stream_session *, const char *host, uint16_t port);
/**
* stop forwarding to all remote endpoints
*/
void i2psam_stop_forwarding_all(struct i2psam_stream_session *);
/**
* get remote destination for our stream session
* @return must be free()'d by caller when done with it
*/
struct i2psam_destination *i2psam_get_my_destination(struct i2psam_stream_session *);
/**
* blocking write a buffer of data with an i2psocket
* @param data buffer to be written
* @param dlen size of buffer
*/
void i2psam_write(struct i2psam_socket *, const char *data, size_t dlen);
/**
* blocking read on an i2p socket
* @param pointer to size read
* @return pointer to read segment, must be free()'d when done if error while reading returns nullptr
*/
char *i2psam_read(struct i2psam_socket *, size_t *dlen);
/**
* close an i2p socket, does not free()
*/
void i2psam_socket_close(struct i2psam_socket *);
/**
* @return 1 if an i2p socket is okay otherwise returns 0
*/
int i2psam_socket_is_ok(struct i2psam_socket *);
/**
* free() an i2p socket, must be closed
*/
void i2psam_socket_free(struct i2psam_socket *);
/**
* get private key for destination as null terminated base64 string
* @return must be free()'d by caller when done
*/
const char *i2psam_destination_priv(struct i2psam_destination *);
/**
* get public base64 destination blob as null terminated string
* @return must be free()'d by caller when done
*/
const char *i2psam_destination_pub(struct i2psam_destination *);
void i2psam_destination_free(struct i2psam_destination *);
#endif // I2PSAM_C_H