Changeset 518


Ignore:
Timestamp:
11/12/09 15:44:48 (3 years ago)
Author:
eagle
Message:
 
Location:
branches/i2prep/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/i2prep/src/ocat.c

    r514 r518  
    381381   if ((s = strchr(CNF(onion_url), '.'))) 
    382382         *s = '\0'; 
     383   // set Tor as default network if no TLD is specified 
     384   else 
     385      CNF(conn_enabled) = PT_TOR_B; 
    383386   if (strlen(CNF(onion_url)) != 16) 
    384387      log_msg(LOG_ERR, "parameter seems not to be valid onion hostname"), exit(1); 
  • branches/i2prep/src/ocat.h

    r514 r518  
    112112#define TOR_PREFIX4_MASK 0xff000000 
    113113#endif 
     114//! hidden service TLD 
     115#define ONION_TLD "onion" 
    114116//! Length of an .onion-URL (without ".onion" and '\0') 
    115117#define ONION_URL_LEN 16 
     
    118120//! Total length of .onion-URL (equal to ONION_NAME_SIZE) 
    119121#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 
    120129 
    121130#define MAXPEERS 1024 
     
    128137//! SOCKS port of TOR proxy 
    129138#define TOR_SOCKS_PORT 9050 
     139#define I2P_SOCKS_PORT 9051 
    130140#ifdef __OpenBSD__ 
    131141#define OCAT_UNAME "_tor" 
     
    235245#define VERSION_STRING_LEN 256 
    236246 
    237 typedef enum PeerType {PT_TOR, PT_I2P} PeerType_t; 
     247typedef 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 
     251typedef 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; 
    238278 
    239279struct OcatSetup 
     
    243283   uint32_t fhd_key[2]; 
    244284   int fhd_key_len; 
    245    //! TCP port of SOCKS port of local Tor proxy 
    246    //uint16_t tor_socks_port; 
    247    //! reload port of OnionCat listening for connections 
    248    //uint16_t ocat_listen_port; 
    249    //! virtual port of OnionCat hidden service 
    250    uint16_t ocat_dest_port; 
    251285   //! local port of controller interface 
    252286   uint16_t ocat_ctrl_port; 
    253    //! file descriptors of TUN device (usually tunfd[0] == tunfd[1]) 
    254    int tunfd[2]; 
    255287   int debug_level; 
    256288   //! user name to change uid to 
    257289   char *usrname; 
    258    char onion_url[ONION_NAME_SIZE]; 
    259    struct in6_addr ocat_addr; 
    260290   //! flag to create connection log 
    261291   int create_clog; 
     
    264294   int controller; 
    265295   char *ocat_dir; 
    266    //! name of tunnel charcter device 
    267    char *tun_dev; 
    268    //! tunnel interface name 
    269    char tunname[SIZE_256]; 
    270296   int ipv4_enable; 
    271297   struct in_addr ocat_addr4; 
     
    274300   int config_read; 
    275301   int use_tap; 
    276    //! local OnionCat MAC address 
    277    uint8_t ocat_hwaddr[ETHER_ADDR_LEN]; 
    278302   char *pid_file; 
    279303   int create_pid_file; 
     
    287311   time_t uptime; 
    288312   char *frandn; 
    289    //! destination socket address of Tor's SOCKS port 
    290    union 
    291    { 
    292       struct sockaddr_in *socks_dst; 
    293       struct sockaddr_in6 *socks_dst6; 
    294    }; 
    295    //! local listening socket address for incoming connections 
    296    struct sockaddr **oc_listen; 
    297    int *oc_listen_fd; 
    298    int oc_listen_cnt; 
    299313   int rand_addr; 
    300314   char version[VERSION_STRING_LEN]; 
     
    306320   int *ctrl_listen_fd; 
    307321   int ctrl_listen_cnt; 
    308    //! communication pipe for socks "selected" connector 
    309    int socksfd[2]; 
     322   int conn_enabled; 
     323   NetConn_t conn[2]; 
    310324}; 
    311325 
     
    359373   unsigned inm; 
    360374   unsigned outm; 
    361    PeerType_t type; 
     375   peer_t type; 
    362376} OcatPeer_t; 
    363377 
  • branches/i2prep/src/ocatsetup.c

    r514 r518  
    4444   // fhd_key_len 
    4545   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 
    5248   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, 
    5650   NULL, 1, 
    5751#ifdef __CYGWIN__ 
     
    6054   0,                                      // use_tap 
    6155#endif 
    62    {0x00, 0x00, 0x6c, 0x00, 0x00, 0x00},   // ocat_hwaddr (OnionCat MAC address) 
    6356   PID_FILE,                               // pid_file 
    6457   0,                                      // create_pid_file 
     
    7164#endif 
    7265   { 
    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            */ 
    7766      {{{0xfd, 0x87, 0xd8, 0x7e, 0xeb, 0x43, 
    7867           0xf6, 0x83, 0x64, 0xac, 0x73, 0xf9, 0x61, 0xac, 0x9a, 0x00}}}  // initial permanent peer "62bwjldt7fq2zgqa" (dot.cat) 
     
    8069   0, 
    8170   "/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 
    9072   0, 
    9173   {0}, 
     
    10587#endif 
    10688   , 
    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   } 
    109136}; 
    110137 
     
    125152   setup_.uptime = time(NULL); 
    126153 
    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); 
    130157#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); 
    132159#endif 
    133160 
     
    166193   inet_ntop(AF_INET, &setup_.ocat_addr4, ip, SBUF); 
    167194   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); 
    170197 
    171198   if (setup_.logf == stderr) 
     
    183210         //"tor_socks_port    = %d\n" 
    184211         //"ocat_listen_port       = %d\n" 
    185          "ocat_dest_port         = %d\n" 
    186212         "ocat_ctrl_port         = %d\n" 
    187          "tunfd[0]               = %d\n" 
    188          "tunfd[1]               = %d\n" 
    189213         "debug_level            = %d\n" 
    190214         "usrname                = \"%s\"\n" 
    191          "onion_url              = \"%s\"\n" 
    192215         "ocat_addr              = %s\n" 
    193216         "create_clog            = %d\n" 
     
    195218         "controller             = %d\n" 
    196219         "ocat_dir               = \"%s\"\n" 
    197          "tun_dev                = \"%s\"\n" 
    198          "tunname                = \"%s\"\n" 
    199220         "ipv4_enable            = %d\n" 
    200221         "ocat_addr4             = %s\n" 
     
    217238         //setup_.tor_socks_port, 
    218239         //setup_.ocat_listen_port, 
    219          setup_.ocat_dest_port, 
    220240         setup_.ocat_ctrl_port, 
    221          setup_.tunfd[0], setup_.tunfd[1], 
    222241         setup_.debug_level, 
    223242         setup_.usrname, 
    224          setup_.onion_url, 
    225243         ip6, 
    226244         setup_.create_clog, 
     
    228246         setup_.controller, 
    229247         setup_.ocat_dir, 
    230          setup_.tun_dev, 
    231          setup_.tunname, 
    232248         setup_.ipv4_enable, 
    233249         ip, 
     
    250266      if (inet_ntop(AF_INET6, &setup_.root_peer[i], rp, SBUF)) 
    251267         fprintf(f, "root_peer[%d]           = %s\n", i, rp); 
    252  
     268/* 
    253269   if (inet_ntops((struct sockaddr*) setup_.socks_dst, &sas)) 
    254270   { 
     
    272288         log_msg(LOG_WARNING, "could not convert struct sockaddr: \"%s\"", strerror(errno)); 
    273289      fprintf(f, "oc_listen_fd[%d]        = %d\n", i, CNF(oc_listen_fd)[i]); 
    274    } 
     290   }*/ 
    275291} 
    276292 
  • branches/i2prep/src/ocatv6conv.c

    r500 r518  
    4141      15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 };   
    4242static const struct in6_addr tor_prefix_ = TOR_PREFIX; 
     43static const struct in6_addr i2p_prefix_ = I2P_PREFIX; 
    4344 
    4445 
     
    5253{ 
    5354   memcpy(addr, &tor_prefix_, 6); 
     55} 
     56 
     57 
     58void set_i2p_prefix(struct in6_addr *addr) 
     59{ 
     60   memcpy(addr, &i2p_prefix_, 6); 
    5461} 
    5562 
     
    7279 
    7380 
    74 int oniontipv6(const char *onion, struct in6_addr *ip6) 
     81int b32_decode(const char *onion, struct in6_addr *ip6) 
    7582{ 
    7683   int i, j; 
     
    8895      *(((char*) ip6) + 15) |= j; 
    8996   } 
     97   return 0; 
     98} 
     99 
     100 
     101int oniontipv6(const char *onion, struct in6_addr *ip6) 
     102{ 
     103   b32_decode(onion, ip6); 
    90104   set_tor_prefix(ip6); 
    91    return 0; 
     105} 
     106 
     107 
     108int i2ptipv6(const char *onion, struct in6_addr *ip6) 
     109{ 
     110   b32_decode(onion, ip6); 
     111   set_i2p_prefix(ip6); 
    92112} 
    93113 
     
    148168 
    149169 
     170peer_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 
    150184/*! Convert struct sockaddr to stuct sockaddr_str which holds the address 
    151185 *  in string representation. 
Note: See TracChangeset for help on using the changeset viewer.