Changeset 518
- Timestamp:
- 11/12/09 15:44:48 (3 years ago)
- Location:
- branches/i2prep/src
- Files:
-
- 4 edited
-
ocat.c (modified) (1 diff)
-
ocat.h (modified) (10 diffs)
-
ocatsetup.c (modified) (13 diffs)
-
ocatv6conv.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/i2prep/src/ocat.c
r514 r518 381 381 if ((s = strchr(CNF(onion_url), '.'))) 382 382 *s = '\0'; 383 // set Tor as default network if no TLD is specified 384 else 385 CNF(conn_enabled) = PT_TOR_B; 383 386 if (strlen(CNF(onion_url)) != 16) 384 387 log_msg(LOG_ERR, "parameter seems not to be valid onion hostname"), exit(1); -
branches/i2prep/src/ocat.h
r514 r518 112 112 #define TOR_PREFIX4_MASK 0xff000000 113 113 #endif 114 //! hidden service TLD 115 #define ONION_TLD "onion" 114 116 //! Length of an .onion-URL (without ".onion" and '\0') 115 117 #define ONION_URL_LEN 16 … … 118 120 //! Total length of .onion-URL (equal to ONION_NAME_SIZE) 119 121 #define ONION_NAME_LEN ONION_NAME_SIZE 122 //! hidden service TLD 123 #define I2P_TLD "oc.b32.i2p" 124 //! Length of an .onion-URL (without ".onion" and '\0') 125 #define I2P_URL_LEN 16 126 //! Total length of .onion-URL 127 #define I2P_NAME_SIZE (I2P_URL_LEN + 11) 128 120 129 121 130 #define MAXPEERS 1024 … … 128 137 //! SOCKS port of TOR proxy 129 138 #define TOR_SOCKS_PORT 9050 139 #define I2P_SOCKS_PORT 9051 130 140 #ifdef __OpenBSD__ 131 141 #define OCAT_UNAME "_tor" … … 235 245 #define VERSION_STRING_LEN 256 236 246 237 typedef enum PeerType {PT_TOR, PT_I2P} PeerType_t; 247 typedef enum peer{PT_TOR, PT_I2P} peer_t; 248 #define PT_TOR_B (1 << (PT_TOR - 1)) 249 #define PT_I2P_B (1 << (PT_I2P - 1)) 250 251 typedef struct NetConn 252 { 253 peer_t type; 254 int socksfd[2]; 255 //! destination socket address of Tor's SOCKS port 256 union 257 { 258 struct sockaddr_in *socks_dst; 259 struct sockaddr_in6 *socks_dst6; 260 }; 261 //! local listening socket address for incoming connections 262 struct sockaddr **listen; 263 int *listen_fd; 264 int listen_cnt; 265 //! virtual port of OnionCat hidden service 266 uint16_t dest_port; 267 //! file descriptors of TUN device (usually tunfd[0] == tunfd[1]) 268 int tunfd[2]; 269 char host_id[ONION_NAME_SIZE]; 270 struct in6_addr addr; 271 //! name of tunnel charcter device 272 char *tun_dev; 273 //! tunnel interface name 274 char tunname[SIZE_256]; 275 //! local OnionCat MAC address 276 uint8_t hwaddr[ETHER_ADDR_LEN]; 277 } NetConn_t; 238 278 239 279 struct OcatSetup … … 243 283 uint32_t fhd_key[2]; 244 284 int fhd_key_len; 245 //! TCP port of SOCKS port of local Tor proxy246 //uint16_t tor_socks_port;247 //! reload port of OnionCat listening for connections248 //uint16_t ocat_listen_port;249 //! virtual port of OnionCat hidden service250 uint16_t ocat_dest_port;251 285 //! local port of controller interface 252 286 uint16_t ocat_ctrl_port; 253 //! file descriptors of TUN device (usually tunfd[0] == tunfd[1])254 int tunfd[2];255 287 int debug_level; 256 288 //! user name to change uid to 257 289 char *usrname; 258 char onion_url[ONION_NAME_SIZE];259 struct in6_addr ocat_addr;260 290 //! flag to create connection log 261 291 int create_clog; … … 264 294 int controller; 265 295 char *ocat_dir; 266 //! name of tunnel charcter device267 char *tun_dev;268 //! tunnel interface name269 char tunname[SIZE_256];270 296 int ipv4_enable; 271 297 struct in_addr ocat_addr4; … … 274 300 int config_read; 275 301 int use_tap; 276 //! local OnionCat MAC address277 uint8_t ocat_hwaddr[ETHER_ADDR_LEN];278 302 char *pid_file; 279 303 int create_pid_file; … … 287 311 time_t uptime; 288 312 char *frandn; 289 //! destination socket address of Tor's SOCKS port290 union291 {292 struct sockaddr_in *socks_dst;293 struct sockaddr_in6 *socks_dst6;294 };295 //! local listening socket address for incoming connections296 struct sockaddr **oc_listen;297 int *oc_listen_fd;298 int oc_listen_cnt;299 313 int rand_addr; 300 314 char version[VERSION_STRING_LEN]; … … 306 320 int *ctrl_listen_fd; 307 321 int ctrl_listen_cnt; 308 //! communication pipe for socks "selected" connector309 int socksfd[2];322 int conn_enabled; 323 NetConn_t conn[2]; 310 324 }; 311 325 … … 359 373 unsigned inm; 360 374 unsigned outm; 361 PeerType_t type;375 peer_t type; 362 376 } OcatPeer_t; 363 377 -
branches/i2prep/src/ocatsetup.c
r514 r518 44 44 // fhd_key_len 45 45 sizeof(uint32_t), 46 //TOR_SOCKS_PORT, 47 //OCAT_LISTEN_PORT, 48 OCAT_DEST_PORT, OCAT_CTRL_PORT, 49 //! default tunfd is stdin/stdout 50 {0, 1}, 51 //! default debug level 46 OCAT_CTRL_PORT, 47 //! default debug level 52 48 LOG_DEBUG, 53 OCAT_UNAME, {0}, {{{0}}}, 0, 0, 1, OCAT_DIR, TUN_DEV, 54 {'\0'}, // tunname 55 0, TOR_PREFIX4, TOR_PREFIX4_MASK, 49 OCAT_UNAME, 0, 0, 1, OCAT_DIR, 0, TOR_PREFIX4, TOR_PREFIX4_MASK, 56 50 NULL, 1, 57 51 #ifdef __CYGWIN__ … … 60 54 0, // use_tap 61 55 #endif 62 {0x00, 0x00, 0x6c, 0x00, 0x00, 0x00}, // ocat_hwaddr (OnionCat MAC address)63 56 PID_FILE, // pid_file 64 57 0, // create_pid_file … … 71 64 #endif 72 65 { 73 /*74 {{{0xfd, 0x87, 0xd8, 0x7e, 0xeb, 0x43,75 0xed, 0xb1, 0x08, 0xe4, 0x35, 0x88, 0xe5, 0x46, 0x35, 0xca}}}, // initial permanent peer "5wyqrzbvrdsumnok" (mail.root-servers.cat)76 */77 66 {{{0xfd, 0x87, 0xd8, 0x7e, 0xeb, 0x43, 78 67 0xf6, 0x83, 0x64, 0xac, 0x73, 0xf9, 0x61, 0xac, 0x9a, 0x00}}} // initial permanent peer "62bwjldt7fq2zgqa" (dot.cat) … … 80 69 0, 81 70 "/dev/urandom", 82 {(struct sockaddr_in*) &socks_dst6_}, 83 // oc_listen 84 NULL, 85 // oc_listen_fd 86 NULL, 87 // oc_listen_cnt 88 0, 89 //! rand_addr 71 //! rand_addr 90 72 0, 91 73 {0}, … … 105 87 #endif 106 88 , 107 // socksfd 108 {-1, -1} 89 0 90 { 91 { 92 PT_TOR, 93 // socksfd 94 {-1, -1}, 95 {(struct sockaddr_in*) &socks_dst6_}, 96 // oc_listen 97 NULL, 98 // oc_listen_fd 99 NULL, 100 // oc_listen_cnt 101 0, 102 OCAT_DEST_PORT, 103 //! default tunfd is stdin/stdout 104 {0, 1}, 105 //! onion_url 106 {'\0'}, 107 //! ocat_addr 108 {{{0}}}, 109 TUN_DEV, 110 {'\0'}, // tunname 111 {0x00, 0x00, 0x6c, 0x00, 0x00, 0x00}, // ocat_hwaddr (OnionCat MAC address) 112 }, 113 { 114 PT_I2P, 115 // socksfd 116 {-1, -1}, 117 {(struct sockaddr_in*) &socks_dst6_}, 118 // oc_listen 119 NULL, 120 // oc_listen_fd 121 NULL, 122 // oc_listen_cnt 123 0, 124 OCAT_DEST_PORT, 125 //! default tunfd is stdin/stdout 126 {0, 1}, 127 //! onion_url 128 {'\0'}, 129 //! ocat_addr 130 {{{0}}}, 131 TUN_DEV, 132 {'\0'}, // tunname 133 {0x00, 0x00, 0x6c, 0x00, 0x00, 0x00}, // ocat_hwaddr (OnionCat MAC address) 134 }, 135 } 109 136 }; 110 137 … … 125 152 setup_.uptime = time(NULL); 126 153 127 setup_. socks_dst->sin_family = AF_INET;128 setup_. socks_dst->sin_port = htons(TOR_SOCKS_PORT);129 setup_. socks_dst->sin_addr.s_addr = htonl(INADDR_LOOPBACK);154 setup_.conn[PT_TOR].socks_dst->sin_family = AF_INET; 155 setup_.conn[PT_TOR].socks_dst->sin_port = htons(TOR_SOCKS_PORT); 156 setup_.conn[PT_TOR].socks_dst->sin_addr.s_addr = htonl(INADDR_LOOPBACK); 130 157 #ifdef HAVE_SIN_LEN 131 setup_. socks_dst->sin_len = SOCKADDR_SIZE(setup_.socks_dst);158 setup_.conn[PT_TOR].socks_dst->sin_len = SOCKADDR_SIZE(setup_.conn[PT_TOR].socks_dst); 132 159 #endif 133 160 … … 166 193 inet_ntop(AF_INET, &setup_.ocat_addr4, ip, SBUF); 167 194 inet_ntop(AF_INET, &setup_.ocat_addr4_mask, nm, SBUF); 168 inet_ntop(AF_INET6, &setup_. ocat_addr, ip6, SBUF);169 ether_ntoa_r((struct ether_addr*) setup_. ocat_hwaddr, hw);195 inet_ntop(AF_INET6, &setup_.conn[PT_TOR].ocat_addr, ip6, SBUF); 196 ether_ntoa_r((struct ether_addr*) setup_.conn[PT_TOR].ocat_hwaddr, hw); 170 197 171 198 if (setup_.logf == stderr) … … 183 210 //"tor_socks_port = %d\n" 184 211 //"ocat_listen_port = %d\n" 185 "ocat_dest_port = %d\n"186 212 "ocat_ctrl_port = %d\n" 187 "tunfd[0] = %d\n"188 "tunfd[1] = %d\n"189 213 "debug_level = %d\n" 190 214 "usrname = \"%s\"\n" 191 "onion_url = \"%s\"\n"192 215 "ocat_addr = %s\n" 193 216 "create_clog = %d\n" … … 195 218 "controller = %d\n" 196 219 "ocat_dir = \"%s\"\n" 197 "tun_dev = \"%s\"\n"198 "tunname = \"%s\"\n"199 220 "ipv4_enable = %d\n" 200 221 "ocat_addr4 = %s\n" … … 217 238 //setup_.tor_socks_port, 218 239 //setup_.ocat_listen_port, 219 setup_.ocat_dest_port,220 240 setup_.ocat_ctrl_port, 221 setup_.tunfd[0], setup_.tunfd[1],222 241 setup_.debug_level, 223 242 setup_.usrname, 224 setup_.onion_url,225 243 ip6, 226 244 setup_.create_clog, … … 228 246 setup_.controller, 229 247 setup_.ocat_dir, 230 setup_.tun_dev,231 setup_.tunname,232 248 setup_.ipv4_enable, 233 249 ip, … … 250 266 if (inet_ntop(AF_INET6, &setup_.root_peer[i], rp, SBUF)) 251 267 fprintf(f, "root_peer[%d] = %s\n", i, rp); 252 268 /* 253 269 if (inet_ntops((struct sockaddr*) setup_.socks_dst, &sas)) 254 270 { … … 272 288 log_msg(LOG_WARNING, "could not convert struct sockaddr: \"%s\"", strerror(errno)); 273 289 fprintf(f, "oc_listen_fd[%d] = %d\n", i, CNF(oc_listen_fd)[i]); 274 } 290 }*/ 275 291 } 276 292 -
branches/i2prep/src/ocatv6conv.c
r500 r518 41 41 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }; 42 42 static const struct in6_addr tor_prefix_ = TOR_PREFIX; 43 static const struct in6_addr i2p_prefix_ = I2P_PREFIX; 43 44 44 45 … … 52 53 { 53 54 memcpy(addr, &tor_prefix_, 6); 55 } 56 57 58 void set_i2p_prefix(struct in6_addr *addr) 59 { 60 memcpy(addr, &i2p_prefix_, 6); 54 61 } 55 62 … … 72 79 73 80 74 int oniontipv6(const char *onion, struct in6_addr *ip6)81 int b32_decode(const char *onion, struct in6_addr *ip6) 75 82 { 76 83 int i, j; … … 88 95 *(((char*) ip6) + 15) |= j; 89 96 } 97 return 0; 98 } 99 100 101 int oniontipv6(const char *onion, struct in6_addr *ip6) 102 { 103 b32_decode(onion, ip6); 90 104 set_tor_prefix(ip6); 91 return 0; 105 } 106 107 108 int i2ptipv6(const char *onion, struct in6_addr *ip6) 109 { 110 b32_decode(onion, ip6); 111 set_i2p_prefix(ip6); 92 112 } 93 113 … … 148 168 149 169 170 peer_t check_net_id(char *id_str) 171 { 172 char *s; 173 174 if (!(s = strtok(id_str, "."))) 175 return PT_TOR; 176 if (!strcmp(s, ONION_TLD)) 177 return PT_TOR; 178 if (!strcmp(s, I2P_TLD)) 179 return PT_I2P; 180 return -1; 181 } 182 183 150 184 /*! Convert struct sockaddr to stuct sockaddr_str which holds the address 151 185 * in string representation.
Note: See TracChangeset
for help on using the changeset viewer.
