From 997154f9c5f4c3f0c99920db647799b09e6f8670 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Thu, 13 Oct 2016 15:13:56 +0200 Subject: [PATCH 01/52] added preliminary implementation of chacha20/poly1305 --- libretroshare/src/crypto/chacha20.cpp | 867 ++++++++++++++++++++++++++ libretroshare/src/crypto/chacha20.h | 74 +++ libretroshare/src/libretroshare.pro | 4 + 3 files changed, 945 insertions(+) create mode 100644 libretroshare/src/crypto/chacha20.cpp create mode 100644 libretroshare/src/crypto/chacha20.h diff --git a/libretroshare/src/crypto/chacha20.cpp b/libretroshare/src/crypto/chacha20.cpp new file mode 100644 index 000000000..b2b61e182 --- /dev/null +++ b/libretroshare/src/crypto/chacha20.cpp @@ -0,0 +1,867 @@ +/* + * RetroShare C++ File sharing default variables + * + * file_sharing/file_sharing_defaults.h + * + * Copyright 2016 by Mr.Alice + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare.project@gmail.com". + * + */ +#include +#include +#include +#include +#include +#include + +#include +#include + +#define rotl(x,n) { x = (x << n) | (x >> (-n & 31)) ;} + +namespace librs { +namespace crypto { + +/*! + * \brief The uint256_32 struct + * This structure represents 256bits integers, to be used for computing poly1305 authentication tags. + */ +struct uint256_32 +{ + uint64_t b[8] ; + + uint256_32() { memset(&b[0],0,8*sizeof(uint64_t)) ; } + + uint256_32(uint32_t b7,uint32_t b6,uint32_t b5,uint32_t b4,uint32_t b3,uint32_t b2,uint32_t b1,uint32_t b0) + { + b[0]=b0; b[1]=b1; b[2]=b2; b[3]=b3; + b[4]=b4; b[5]=b5; b[6]=b6; b[7]=b7; + } + + static uint256_32 random() // non cryptographically secure random. Just for testing. + { + uint256_32 r ; + for(uint32_t i=0;i<8;++i) + r.b[i] = lrand48() & 0xffffffff ; + + return r; + } + + // constant cost == + bool operator==(const uint256_32& u) + { + bool res = true ; + + if(b[0] != u.b[0]) res = false ; + if(b[1] != u.b[1]) res = false ; + if(b[2] != u.b[2]) res = false ; + if(b[3] != u.b[3]) res = false ; + if(b[4] != u.b[4]) res = false ; + if(b[5] != u.b[5]) res = false ; + if(b[6] != u.b[6]) res = false ; + if(b[7] != u.b[7]) res = false ; + + return res ; + } + + // Constant cost sum. + // + void operator +=(const uint256_32& u) + { + b[0] += u.b[0]; + b[1] += u.b[1] + (b[0]>>32); + b[2] += u.b[2] + (b[1]>>32); + b[3] += u.b[3] + (b[2]>>32); + b[4] += u.b[4] + (b[3]>>32); + b[5] += u.b[5] + (b[4]>>32); + b[6] += u.b[6] + (b[5]>>32); + b[7] += u.b[7] + (b[6]>>32); + + b[0] &= 0xffffffff; + b[1] &= 0xffffffff; + b[2] &= 0xffffffff; + b[3] &= 0xffffffff; + b[4] &= 0xffffffff; + b[5] &= 0xffffffff; + b[6] &= 0xffffffff; + b[7] &= 0xffffffff; + } + void operator -=(const uint256_32& u) { *this += ~u ; *this += uint256_32(0,0,0,0,0,0,0,1); } + + bool operator<(const uint256_32& u) const + { + for(int i=7;i>=0;--i) + if(b[i] < u.b[i]) + return true ; + else + if(b[i] > u.b[i]) + return false ; + + return false ; + } + uint256_32 operator~() const + { + uint256_32 r(*this) ; + + r.b[0] = (~b[0]) & 0xffffffff ; + r.b[1] = (~b[1]) & 0xffffffff ; + r.b[2] = (~b[2]) & 0xffffffff ; + r.b[3] = (~b[3]) & 0xffffffff ; + r.b[4] = (~b[4]) & 0xffffffff ; + r.b[5] = (~b[5]) & 0xffffffff ; + r.b[6] = (~b[6]) & 0xffffffff ; + r.b[7] = (~b[7]) & 0xffffffff ; + + return r ; + } + + void poly1305clamp() + { + b[0] &= 0x0fffffff; + b[1] &= 0x0ffffffc; + b[2] &= 0x0ffffffc; + b[3] &= 0x0ffffffc; + } + // Constant cost product. + // + void operator *=(const uint256_32& u) + { + uint256_32 r ; + + for(int i=0;i<8;++i) + for(int j=0;j<8;++j) + if(i+j < 8) + { + uint64_t s = u.b[j]*b[i] ; + + uint256_32 partial ; + partial.b[i+j] = (s & 0xffffffff) ; + + if(i+j+1 < 8) + partial.b[i+j+1] = (s >> 32) ; + + r += partial; + } + *this = r; + + assert(!(b[0] & 0xffffffff00000000)) ; + assert(!(b[1] & 0xffffffff00000000)) ; + assert(!(b[2] & 0xffffffff00000000)) ; + assert(!(b[3] & 0xffffffff00000000)) ; + assert(!(b[4] & 0xffffffff00000000)) ; + assert(!(b[5] & 0xffffffff00000000)) ; + assert(!(b[6] & 0xffffffff00000000)) ; + assert(!(b[7] & 0xffffffff00000000)) ; + } + + static void print(const uint256_32& s) + { + fprintf(stdout,"%08x %08x %08x %08x %08x %08x %08x %08x",(uint32_t)s.b[7],(uint32_t)s.b[6],(uint32_t)s.b[5],(uint32_t)s.b[4], + (uint32_t)s.b[3],(uint32_t)s.b[2],(uint32_t)s.b[1],(uint32_t)s.b[0]) ; + } + static int max_non_zero_of_height_bits(uint8_t s) + { + for(int i=7;i>=0;--i) + if((s & (1<=0;--c) + if(b[c] != 0) + { + if( (b[c] & 0xff000000) != 0) return c*32 + 3*8 + max_non_zero_of_height_bits(b[c] >> 24) ; + if( (b[c] & 0x00ff0000) != 0) return c*32 + 2*8 + max_non_zero_of_height_bits(b[c] >> 16) ; + if( (b[c] & 0x0000ff00) != 0) return c*32 + 1*8 + max_non_zero_of_height_bits(b[c] >> 8) ; + + return c*32 + 0*8 + max_non_zero_of_height_bits(b[c]) ; + } + return -1; + } + void lshift() + { + int r = 0 ; + + for(int i=0;i<8;++i) + { + uint32_t r1 = (b[i] >> 31) ; + b[i] = (b[i] << 1) & 0xffffffff; + b[i] += r ; + r = r1 ; + } + } + void rshift() + { + uint32_t r = 0 ; + + for(int i=7;i>=0;--i) + { + uint32_t r1 = b[i] & 0x1; + b[i] >>= 1 ; + b[i] += r << 31; + r = r1 ; + } + } +}; + +// Compute quotient and modulo of n by p where both n and p are 256bits integers. +// +static void quotient(const uint256_32& n,const uint256_32& p,uint256_32& q,uint256_32& r) +{ + // simple algorithm: add up multiples of u while keeping below *this. Once done, substract. + + r = n ; + q = uint256_32(0,0,0,0,0,0,0,0) ; + + int bmax = n.max_non_zero_bit() - p.max_non_zero_bit(); + + uint256_32 m(0,0,0,0,0,0,0,1) ; + uint256_32 d = p ; + + for(int i=0;i=0;--b,d.rshift(),m.rshift()) + if(! (r < d)) + { + r -= d ; + q += m ; + } +} + +class chacha20_state +{ +public: + uint32_t c[16] ; + + chacha20_state(uint8_t key[32],uint32_t block_counter,uint8_t nounce[12]) + { + c[0] = 0x61707865 ; + c[1] = 0x3320646e ; + c[2] = 0x79622d32 ; + c[3] = 0x6b206574 ; + + c[ 4] = (uint32_t)key[0 ] + (((uint32_t)key[1 ])<<8) + (((uint32_t)key[2 ])<<16) + (((uint32_t)key[3 ])<<24); + c[ 5] = (uint32_t)key[4 ] + (((uint32_t)key[5 ])<<8) + (((uint32_t)key[6 ])<<16) + (((uint32_t)key[7 ])<<24); + c[ 6] = (uint32_t)key[8 ] + (((uint32_t)key[9 ])<<8) + (((uint32_t)key[10])<<16) + (((uint32_t)key[11])<<24); + c[ 7] = (uint32_t)key[12] + (((uint32_t)key[13])<<8) + (((uint32_t)key[14])<<16) + (((uint32_t)key[15])<<24); + c[ 8] = (uint32_t)key[16] + (((uint32_t)key[17])<<8) + (((uint32_t)key[18])<<16) + (((uint32_t)key[19])<<24); + c[ 9] = (uint32_t)key[20] + (((uint32_t)key[21])<<8) + (((uint32_t)key[22])<<16) + (((uint32_t)key[23])<<24); + c[10] = (uint32_t)key[24] + (((uint32_t)key[25])<<8) + (((uint32_t)key[26])<<16) + (((uint32_t)key[27])<<24); + c[11] = (uint32_t)key[28] + (((uint32_t)key[29])<<8) + (((uint32_t)key[30])<<16) + (((uint32_t)key[31])<<24); + + c[12] = block_counter ; + + c[13] = (uint32_t)nounce[0 ] + (((uint32_t)nounce[1 ])<<8) + (((uint32_t)nounce[2 ])<<16) + (((uint32_t)nounce[3 ])<<24); + c[14] = (uint32_t)nounce[4 ] + (((uint32_t)nounce[5 ])<<8) + (((uint32_t)nounce[6 ])<<16) + (((uint32_t)nounce[7 ])<<24); + c[15] = (uint32_t)nounce[8 ] + (((uint32_t)nounce[9 ])<<8) + (((uint32_t)nounce[10])<<16) + (((uint32_t)nounce[11])<<24); + } +}; + +static void quarter_round(uint32_t& a,uint32_t& b,uint32_t& c,uint32_t& d) +{ + a += b ; d ^= a; rotl(d,16) ; //d <<<=16 ; + c += d ; b ^= c; rotl(b,12) ; //b <<<=12 ; + a += b ; d ^= a; rotl(d,8) ; //d <<<=8 ; + c += d ; b ^= c; rotl(b,7) ; //b <<<=7 ; +} + +static void apply_20_rounds(chacha20_state& s) +{ + for(uint32_t i=0;i<10;++i) + { + quarter_round(s.c[ 0],s.c[ 4],s.c[ 8],s.c[12]) ; + quarter_round(s.c[ 1],s.c[ 5],s.c[ 9],s.c[13]) ; + quarter_round(s.c[ 2],s.c[ 6],s.c[10],s.c[14]) ; + quarter_round(s.c[ 3],s.c[ 7],s.c[11],s.c[15]) ; + quarter_round(s.c[ 0],s.c[ 5],s.c[10],s.c[15]) ; + quarter_round(s.c[ 1],s.c[ 6],s.c[11],s.c[12]) ; + quarter_round(s.c[ 2],s.c[ 7],s.c[ 8],s.c[13]) ; + quarter_round(s.c[ 3],s.c[ 4],s.c[ 9],s.c[14]) ; + } +} + +static void print(const chacha20_state& s) +{ + fprintf(stdout,"%08x %08x %08x %08x\n",s.c[0 ],s.c[1 ],s.c[2 ],s.c[3 ]) ; + fprintf(stdout,"%08x %08x %08x %08x\n",s.c[4 ],s.c[5 ],s.c[6 ],s.c[7 ]) ; + fprintf(stdout,"%08x %08x %08x %08x\n",s.c[8 ],s.c[9 ],s.c[10],s.c[11]) ; + fprintf(stdout,"%08x %08x %08x %08x\n",s.c[12],s.c[13],s.c[14],s.c[15]) ; +} + +static void add(chacha20_state& s,const chacha20_state& t) { for(uint32_t i=0;i<16;++i) s.c[i] += t.c[i] ; } + +static uint8_t read16bits(char s) +{ + if(s >= '0' && s <= '9') + return s - '0' ; + else if(s >= 'a' && s <= 'f') + return s - 'a' + 10 ; + else if(s >= 'A' && s <= 'F') + return s - 'A' + 10 ; + else + throw std::runtime_error("Not an hex string!") ; +} + +// static uint256_32 create_256bit_int(const std::string& s) +// { +// uint256_32 r(0,0,0,0,0,0,0,0) ; +// +// fprintf(stdout,"Scanning %s\n",s.c_str()) ; +// +// for(int i=0;i<(int)s.length();++i) +// { +// uint32_t byte = (s.length() -1 - i)/2 ; +// uint32_t p = byte/4 ; +// uint32_t val; +// +// if(p >= 8) +// continue ; +// +// val = read16bits(s[i]) ; +// +// r.b[p] |= (( (val << (( (s.length()-i+1)%2)*4))) << (8*byte)) ; +// } +// +// return r; +// } +// static uint256_32 create_256bit_int_from_serialized(const std::string& s) +// { +// uint256_32 r(0,0,0,0,0,0,0,0) ; +// +// fprintf(stdout,"Scanning %s\n",s.c_str()) ; +// +// for(int i=0;i<(int)s.length();i+=3) +// { +// int byte = i/3 ; +// int p = byte/4 ; +// int sub_byte = byte - 4*p ; +// +// uint8_t b1 = read16bits(s[i+0]) ; +// uint8_t b2 = read16bits(s[i+1]) ; +// uint32_t b = (b1 << 4) + b2 ; +// +// r.b[p] |= ( b << (8*sub_byte)) ; +// } +// return r ; +// } + +void chacha20_encrypt(uint8_t key[32], uint32_t block_counter, uint8_t nonce[12], uint8_t *data, uint32_t size) +{ + for(uint32_t i=0;i> (8*(k%4))) & 0xff) ; + } +} + +void poly1305_tag(uint8_t key[32],uint8_t *message,uint32_t size,uint8_t tag[16]) +{ + uint256_32 r( 0,0,0,0, + ((uint32_t)key[12] << 0) + ((uint32_t)key[13] << 8) + ((uint32_t)key[14] << 16) + ((uint32_t)key[15] << 24), + ((uint32_t)key[ 8] << 0) + ((uint32_t)key[ 9] << 8) + ((uint32_t)key[10] << 16) + ((uint32_t)key[11] << 24), + ((uint32_t)key[ 4] << 0) + ((uint32_t)key[ 5] << 8) + ((uint32_t)key[ 6] << 16) + ((uint32_t)key[ 7] << 24), + ((uint32_t)key[ 0] << 0) + ((uint32_t)key[ 1] << 8) + ((uint32_t)key[ 2] << 16) + ((uint32_t)key[ 3] << 24) + ); + + r.poly1305clamp(); + + uint256_32 s( 0,0,0,0, + ((uint32_t)key[28] << 0) + ((uint32_t)key[29] << 8) + ((uint32_t)key[30] << 16) + ((uint32_t)key[31] << 24), + ((uint32_t)key[24] << 0) + ((uint32_t)key[25] << 8) + ((uint32_t)key[26] << 16) + ((uint32_t)key[27] << 24), + ((uint32_t)key[20] << 0) + ((uint32_t)key[21] << 8) + ((uint32_t)key[22] << 16) + ((uint32_t)key[23] << 24), + ((uint32_t)key[16] << 0) + ((uint32_t)key[17] << 8) + ((uint32_t)key[18] << 16) + ((uint32_t)key[19] << 24) + ); + + uint256_32 p(0,0,0,0x3,0xffffffff,0xffffffff,0xffffffff,0xfffffffb) ; + uint256_32 acc(0,0,0, 0, 0, 0, 0, 0) ; + + for(uint32_t i=0;i<(size+15)/16;++i) + { + uint256_32 block ; + uint32_t j; + + for(j=0;j<16 && i*16+j < size;++j) + block.b[j/4] += ((uint64_t)message[i*16+j]) << (8*(j & 0x3)) ; + + block.b[j/4] += 0x01 << (8*(j& 0x3)); + + acc += block ; + acc *= r ; + + uint256_32 q,rst; + quotient(acc,p,q,rst) ; + acc = rst ; + } + + acc += s ; + + tag[ 0] = (acc.b[0] >> 0) & 0xff ; tag[ 1] = (acc.b[0] >> 8) & 0xff ; tag[ 2] = (acc.b[0] >>16) & 0xff ; tag[ 3] = (acc.b[0] >>24) & 0xff ; + tag[ 4] = (acc.b[1] >> 0) & 0xff ; tag[ 5] = (acc.b[1] >> 8) & 0xff ; tag[ 6] = (acc.b[1] >>16) & 0xff ; tag[ 7] = (acc.b[1] >>24) & 0xff ; + tag[ 8] = (acc.b[2] >> 0) & 0xff ; tag[ 9] = (acc.b[2] >> 8) & 0xff ; tag[10] = (acc.b[2] >>16) & 0xff ; tag[11] = (acc.b[2] >>24) & 0xff ; + tag[12] = (acc.b[3] >> 0) & 0xff ; tag[13] = (acc.b[3] >> 8) & 0xff ; tag[14] = (acc.b[3] >>16) & 0xff ; tag[15] = (acc.b[3] >>24) & 0xff ; +} + +void perform_tests() +{ + std::cerr << "Testing Chacha20" << std::endl; + + // RFC7539 - 2.1.1 + + std::cerr << " quarter round..." ; + + uint32_t a = 0x11111111 ; + uint32_t b = 0x01020304 ; + uint32_t c = 0x9b8d6f43 ; + uint32_t d = 0x01234567 ; + + quarter_round(a,b,c,d) ; + + assert(a == 0xea2a92f4) ; + assert(b == 0xcb1cf8ce) ; + assert(c == 0x4581472e) ; + assert(d == 0x5881c4bb) ; + + std::cerr << " - OK" << std::endl; + + // RFC7539 - 2.3.2 + + std::cerr << " RFC7539 - 2.3.2..." ; + + uint8_t key[32] = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b, \ + 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17, \ + 0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f } ; + uint8_t nounce[12] = { 0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x4a,0x00,0x00,0x00,0x00 } ; + + chacha20_state s(key,1,nounce) ; + chacha20_state t(s) ; + + print(s) ; + + fprintf(stdout,"\n") ; + + apply_20_rounds(s) ; + + print(s) ; + add(t,s) ; + + fprintf(stdout,"\n") ; + + print(t) ; + + std::cerr << " - OK" << std::endl; + + // RFC7539 - 2.4.2 + + std::cerr << " RFC7539 - 2.4.2..." ; + + uint8_t nounce2[12] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x4a,0x00,0x00,0x00,0x00 } ; + + uint8_t plaintext[7*16+2] = { + 0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74, 0x6c, + 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c, 0x61, 0x73, + 0x73, 0x20, 0x6f, 0x66, 0x20, 0x27, 0x39, 0x39, 0x3a, 0x20, 0x49, 0x66, 0x20, 0x49, 0x20, 0x63, + 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x6f, 0x66, 0x66, 0x65, 0x72, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x6f, + 0x6e, 0x6c, 0x79, 0x20, 0x6f, 0x6e, 0x65, 0x20, 0x74, 0x69, 0x70, 0x20, 0x66, 0x6f, 0x72, 0x20, + 0x74, 0x68, 0x65, 0x20, 0x66, 0x75, 0x74, 0x75, 0x72, 0x65, 0x2c, 0x20, 0x73, 0x75, 0x6e, 0x73, + 0x63, 0x72, 0x65, 0x65, 0x6e, 0x20, 0x77, 0x6f, 0x75, 0x6c, 0x64, 0x20, 0x62, 0x65, 0x20, 0x69, + 0x74, 0x2e + }; + + chacha20_encrypt(key,1,nounce2,plaintext,7*16+2) ; + +#ifdef PRINT_RESULTS + fprintf(stdout,"CipherText: \n") ; + + for(uint32_t k=0;k<7*16+2;++k) + { + fprintf(stdout,"%02x ",plaintext[k]) ; + + if( (k % 16) == 15) + fprintf(stdout,"\n") ; + } + fprintf(stdout,"\n") ; +#endif + + uint8_t check_cipher_text[7*16+2] = { + 0x6e, 0x2e, 0x35, 0x9a, 0x25, 0x68, 0xf9, 0x80, 0x41, 0xba, 0x07, 0x28, 0xdd, 0x0d, 0x69, 0x81, + 0xe9, 0x7e, 0x7a, 0xec, 0x1d, 0x43, 0x60, 0xc2, 0x0a, 0x27, 0xaf, 0xcc, 0xfd, 0x9f, 0xae, 0x0b, + 0xf9, 0x1b, 0x65, 0xc5, 0x52, 0x47, 0x33, 0xab, 0x8f, 0x59, 0x3d, 0xab, 0xcd, 0x62, 0xb3, 0x57, + 0x16, 0x39, 0xd6, 0x24, 0xe6, 0x51, 0x52, 0xab, 0x8f, 0x53, 0x0c, 0x35, 0x9f, 0x08, 0x61, 0xd8, + 0x07, 0xca, 0x0d, 0xbf, 0x50, 0x0d, 0x6a, 0x61, 0x56, 0xa3, 0x8e, 0x08, 0x8a, 0x22, 0xb6, 0x5e, + 0x52, 0xbc, 0x51, 0x4d, 0x16, 0xcc, 0xf8, 0x06, 0x81, 0x8c, 0xe9, 0x1a, 0xb7, 0x79, 0x37, 0x36, + 0x5a, 0xf9, 0x0b, 0xbf, 0x74, 0xa3, 0x5b, 0xe6, 0xb4, 0x0b, 0x8e, 0xed, 0xf2, 0x78, 0x5e, 0x42, + 0x87, 0x4d + }; + + for(uint32_t i=0;i<7*16+2;++i) + assert(check_cipher_text[i] == plaintext[i] ); + + std::cerr << " - OK" << std::endl; + + // sums/diffs of numbers + + for(uint32_t i=0;i<100;++i) + { + uint256_32 a = uint256_32::random() ; + uint256_32 b = uint256_32::random() ; +#ifdef PRINT_RESULTS + fprintf(stdout,"Adding ") ; + uint256_32::print(a) ; + fprintf(stdout,"\n to ") ; + uint256_32::print(b) ; +#endif + + uint256_32 c(a) ; + assert(c == a) ; + + c += b ; + +#ifdef PRINT_RESULTS + fprintf(stdout,"\n found ") ; + uint256_32::print(c) ; +#endif + + c -= b ; + +#ifdef PRINT_RESULTS + fprintf(stdout,"\n subst ") ; + uint256_32::print(c) ; + fprintf(stdout,"\n") ; +#endif + + assert(a == a) ; + assert(c == a) ; + } + std::cerr << " Sums / diffs of 256bits numbers OK" << std::endl; + + // check that (a-b)*(c-d) = ac - bc - ad + bd + + for(uint32_t i=0;i<100;++i) + { + uint256_32 a = uint256_32::random(); + uint256_32 b = uint256_32::random(); + uint256_32 c = uint256_32::random(); + uint256_32 d = uint256_32::random(); + + uint256_32 amb(a) ; + amb -= b; + uint256_32 cmd(c) ; + cmd -= d; + uint256_32 ambtcmd(amb); + ambtcmd *= cmd ; + + uint256_32 atc(a) ; atc *= c ; + uint256_32 btc(b) ; btc *= c ; + uint256_32 atd(a) ; atd *= d ; + uint256_32 btd(b) ; btd *= d ; + + uint256_32 atcmbtcmatdpbtd(atc) ; + atcmbtcmatdpbtd -= btc ; + atcmbtcmatdpbtd -= atd ; + atcmbtcmatdpbtd += btd ; + + assert(atcmbtcmatdpbtd == ambtcmd); + } + std::cerr << " (a-b)*(c-d) == ac-bc-ad+bd on random OK" << std::endl; + + // shifts + + for(uint32_t i=0;i<100;++i) + { + uint256_32 x = uint256_32::random(); + uint256_32 y(x) ; + + uint32_t r = x.b[0] & 0x1 ; + x.rshift() ; + x.lshift() ; + + x.b[0] += r ; + + assert(x == y) ; + } + std::cerr << " left/right shifting OK" << std::endl; + + // test modulo by computing modulo and recomputing the product. + + for(uint32_t i=0;i<100;++i) + { + uint256_32 q1(0,0,0,0,0,0,0,0),r1(0,0,0,0,0,0,0,0) ; + + uint256_32 n1 = uint256_32::random(); + uint256_32 p1 = uint256_32::random(); + + if(drand48() < 0.2) + { + p1.b[7] = 0 ; + + if(drand48() < 0.1) + p1.b[6] = 0 ; + } + + quotient(n1,p1,q1,r1) ; +#ifdef PRINT_RESULTS + fprintf(stdout,"result: q=") ; chacha20::uint256_32::print(q1) ; fprintf(stdout," r=") ; chacha20::uint256_32::print(r1) ; fprintf(stdout,"\n") ; +#endif + + uint256_32 res(q1) ; + q1 *= p1 ; + q1 += r1 ; + + assert(q1 == n1) ; + } + std::cerr << " Quotient/modulo on random numbers OK" << std::endl; + + // RFC7539 - 2.5 + // + { + uint8_t key[32] = { 0x85,0xd6,0xbe,0x78,0x57,0x55,0x6d,0x33,0x7f,0x44,0x52,0xfe,0x42,0xd5,0x06,0xa8,0x01,0x03,0x80,0x8a,0xfb,0x0d,0xb2,0xfd,0x4a,0xbf,0xf6,0xaf,0x41,0x49,0xf5,0x1b } ; + uint8_t tag[16] ; + std::string msg("Cryptographic Forum Research Group") ; + + poly1305_tag(key,(uint8_t*)msg.c_str(),msg.length(),tag) ; + + uint8_t test_tag[16] = { 0xa8,0x06,0x1d,0xc1,0x30,0x51,0x36,0xc6,0xc2,0x2b,0x8b,0xaf,0x0c,0x01,0x27,0xa9 }; + + assert(!memcmp(tag,test_tag,16)) ; + } + + std::cerr << " RFC7539 poly1305 test vector #001 OK" << std::endl; + + // RFC7539 - Poly1305 test vector #1 + // + + { + uint8_t key[32] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } ; + uint8_t tag[16] ; + uint8_t text[64] ; + memset(text,0,64) ; + + poly1305_tag(key,text,64,tag) ; + + uint8_t test_tag[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; + + assert(!memcmp(tag,test_tag,16)) ; + } + + std::cerr << " RFC7539 poly1305 test vector #002 OK" << std::endl; + + // RFC7539 - Poly1305 test vector #2 + // + + { + uint8_t key[32] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x36,0xe5,0xf6,0xb5,0xc5,0xe0,0x60,0x70,0xf0,0xef,0xca,0x96,0x22,0x7a,0x86,0x3e } ; + uint8_t tag[16] ; + + std::string msg("Any submission to the IETF intended by the Contributor for publication as all or part of an IETF Internet-Draft or RFC and any statement made within the context of an IETF activity is considered an \"IETF Contribution\". Such statements include oral statements in IETF sessions, as well as written and electronic communications made at any time or place, which are addressed to") ; + + poly1305_tag(key,(uint8_t*)msg.c_str(),msg.length(),tag) ; + + uint8_t test_tag[16] = { 0x36,0xe5,0xf6,0xb5,0xc5,0xe0,0x60,0x70,0xf0,0xef,0xca,0x96,0x22,0x7a,0x86,0x3e }; + + assert(!memcmp(tag,test_tag,16)) ; + } + + std::cerr << " RFC7539 poly1305 test vector #003 OK" << std::endl; + + // RFC7539 - Poly1305 test vector #3 + // + + { + uint8_t key[32] = { 0x36,0xe5,0xf6,0xb5,0xc5,0xe0,0x60,0x70,0xf0,0xef,0xca,0x96,0x22,0x7a,0x86,0x3e, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } ; + uint8_t tag[16] ; + + std::string msg("Any submission to the IETF intended by the Contributor for publication as all or part of an IETF Internet-Draft or RFC and any statement made within the context of an IETF activity is considered an \"IETF Contribution\". Such statements include oral statements in IETF sessions, as well as written and electronic communications made at any time or place, which are addressed to") ; + + poly1305_tag(key,(uint8_t*)msg.c_str(),msg.length(),tag) ; + + uint8_t test_tag[16] = { 0xf3,0x47,0x7e,0x7c,0xd9,0x54,0x17,0xaf,0x89,0xa6,0xb8,0x79,0x4c,0x31,0x0c,0xf0 } ; + + assert(!memcmp(tag,test_tag,16)) ; + } + + std::cerr << " RFC7539 poly1305 test vector #004 OK" << std::endl; + // RFC7539 - Poly1305 test vector #4 + // + { + uint8_t key[32] = { 0x1c ,0x92 ,0x40 ,0xa5 ,0xeb ,0x55 ,0xd3 ,0x8a ,0xf3 ,0x33 ,0x88 ,0x86 ,0x04 ,0xf6 ,0xb5 ,0xf0, + 0x47 ,0x39 ,0x17 ,0xc1 ,0x40 ,0x2b ,0x80 ,0x09 ,0x9d ,0xca ,0x5c ,0xbc ,0x20 ,0x70 ,0x75 ,0xc0 }; + uint8_t tag[16] ; + + std::string msg("'Twas brillig, and the slithy toves\nDid gyre and gimble in the wabe:\nAll mimsy were the borogoves,\nAnd the mome raths outgrabe.") ; + + poly1305_tag(key,(uint8_t*)msg.c_str(),msg.length(),tag) ; + + uint8_t test_tag[16] = { 0x45,0x41,0x66,0x9a,0x7e,0xaa,0xee,0x61,0xe7,0x08,0xdc,0x7c,0xbc,0xc5,0xeb,0x62 } ; + + assert(!memcmp(tag,test_tag,16)) ; + } + + std::cerr << " RFC7539 poly1305 test vector #005 OK" << std::endl; + + // RFC7539 - Poly1305 test vector #5 + // + { + uint8_t key[32] = { 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; + uint8_t tag[16] ; + + uint8_t msg[] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff }; + + poly1305_tag(key,msg,16,tag) ; + + uint8_t test_tag[16] = { 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } ; + + assert(!memcmp(tag,test_tag,16)) ; + } + + std::cerr << " RFC7539 poly1305 test vector #006 OK" << std::endl; + + // RFC7539 - Poly1305 test vector #6 + // + { + uint8_t key[32] = { 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff }; + uint8_t tag[16] ; + + uint8_t msg[16] = { 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; + + poly1305_tag(key,msg,16,tag) ; + + uint8_t test_tag[16] = { 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } ; + + assert(!memcmp(tag,test_tag,16)) ; + } + std::cerr << " RFC7539 poly1305 test vector #007 OK" << std::endl; + + // RFC7539 - Poly1305 test vector #7 + // + { + uint8_t key[32] = { 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; + uint8_t tag[16] ; + + uint8_t msg[48] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xf0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } ; + + poly1305_tag(key,msg,48,tag) ; + + uint8_t test_tag[16] = { 0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } ; + + assert(!memcmp(tag,test_tag,16)) ; + } + std::cerr << " RFC7539 poly1305 test vector #008 OK" << std::endl; + + // RFC7539 - Poly1305 test vector #8 + // + { + uint8_t key[32] = { 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; + uint8_t tag[16] ; + + uint8_t msg[48] = { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, + 0xfb,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe, + 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01 } ; + + poly1305_tag(key,msg,48,tag) ; + + uint8_t test_tag[16] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } ; + + assert(!memcmp(tag,test_tag,16)) ; + } + std::cerr << " RFC7539 poly1305 test vector #009 OK" << std::endl; + + // RFC7539 - Poly1305 test vector #9 + // + { + uint8_t key[32] = { 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; + uint8_t tag[16] ; + + uint8_t msg[16] = { 0xfd,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff } ; + + poly1305_tag(key,msg,16,tag) ; + + uint8_t test_tag[16] = { 0xfa,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff } ; + + assert(!memcmp(tag,test_tag,16)) ; + } + std::cerr << " RFC7539 poly1305 test vector #010 OK" << std::endl; + + // RFC7539 - Poly1305 test vector #10 + // + { + uint8_t key[32] = { 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; + uint8_t tag[16] ; + + uint8_t msg[64] = { + 0xE3 ,0x35 ,0x94 ,0xD7 ,0x50 ,0x5E ,0x43 ,0xB9 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00, + 0x33 ,0x94 ,0xD7 ,0x50 ,0x5E ,0x43 ,0x79 ,0xCD ,0x01 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00, + 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00, + 0x01 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 }; + + poly1305_tag(key,msg,64,tag) ; + + uint8_t test_tag[16] = { 0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x55,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } ; + + assert(!memcmp(tag,test_tag,16)) ; + } + std::cerr << " RFC7539 poly1305 test vector #011 OK" << std::endl; + + // RFC7539 - Poly1305 test vector #11 + // + { + uint8_t key[32] = { 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; + uint8_t tag[16] ; + + uint8_t msg[48] = { + 0xE3 ,0x35 ,0x94 ,0xD7 ,0x50 ,0x5E ,0x43 ,0xB9 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00, + 0x33 ,0x94 ,0xD7 ,0x50 ,0x5E ,0x43 ,0x79 ,0xCD ,0x01 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00, + 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 } ; + + poly1305_tag(key,msg,48,tag) ; + + uint8_t test_tag[16] = { 0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } ; + + assert(!memcmp(tag,test_tag,16)) ; + } +} + +} +} + + diff --git a/libretroshare/src/crypto/chacha20.h b/libretroshare/src/crypto/chacha20.h new file mode 100644 index 000000000..77f266193 --- /dev/null +++ b/libretroshare/src/crypto/chacha20.h @@ -0,0 +1,74 @@ +/* + * RetroShare C++ File sharing default variables + * + * crypto/chacha20.h + * + * Copyright 2016 by Mr.Alice + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare.project@gmail.com". + * + */ + +namespace librs +{ + namespace crypto + { + /*! + * \brief chacha20_encrypt + * Performs in place encryption/decryption of the supplied data, using chacha20, using the supplied key and nonce. + * + * \param key secret encryption key. *Should never* be re-used. + * \param block_counter any integer. 0 is fine. + * \param nonce acts as an initialzation vector. /!\ it is extremely important to make sure that this nounce *is* everytime different. Using a purely random value is fine. + * \param data data that gets encrypted/decrypted in place + * \param size size of the data. + */ + static void chacha20_encrypt(uint8_t key[32], uint32_t block_counter, uint8_t nonce[12], uint8_t *data, uint32_t size) ; + + /*! + * \brief poly1305_tag + * Computes an authentication tag for the supplied data, using the given secret key. + * \param key secret key. *Should not* be used multiple times. + * \param message message to generate a tag for + * \param size size of the message + * \param tag place where the tag is stored. + */ + + static void poly1305_tag(uint8_t key[32],uint8_t *message,uint32_t size,uint8_t tag[16]); + + /*! + * \brief AEAD_chacha20_poly1305 + * Provides in-place authenticated encryption using the AEAD construction as described in RFC7539. + * The data is first encrypted in place then 16-padded and concatenated to its size, than concatenated to the + * 16-padded AAD (additional authenticated data) and its size, authenticated using poly1305. + * + * \param key key that is used to derive a one time secret key for poly1305 and that is also used to encrypt the data + * \param nonce nonce. *Should be unique* in order to make the ply1305 key unique. + * \param data data that is encrypted. + * \param size size of the data + * \param tag generated poly1305 tag. + */ + static void AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint32_t data_size,uint8_t *aad,uint8_t *aad_size,uint8_t tag[16]) ; + + /*! + * \brief perform_tests + * Tests all methods in this class, using the tests supplied in RFC7539 + */ + + static void perform_tests() ; + } +} diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 85ff8dce7..1e18835b1 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -380,6 +380,8 @@ HEADERS += ft/ftchunkmap.h \ ft/fttransfermodule.h \ ft/ftturtlefiletransferitem.h +HEADERS += crypto/chacha20.h + HEADERS += directory_updater.h \ directory_list.h \ p3filelists.h @@ -538,6 +540,8 @@ SOURCES += ft/ftchunkmap.cc \ ft/fttransfermodule.cc \ ft/ftturtlefiletransferitem.cc +SOURCES += crypto/chacha20.cpp + SOURCES += chat/distantchat.cc \ chat/p3chatservice.cc \ chat/distributedchat.cc \ From 3ad0a81d8fbd168ead63e8d0bf1ab04ecc8223eb Mon Sep 17 00:00:00 2001 From: mr-alice Date: Wed, 19 Oct 2016 21:30:37 +0200 Subject: [PATCH 02/52] added encryption routine for FT --- libretroshare/src/crypto/chacha20.cpp | 30 ++++--- libretroshare/src/crypto/chacha20.h | 13 ++- libretroshare/src/ft/ftserver.cc | 109 ++++++++++++++++++++++++ libretroshare/src/ft/ftserver.h | 4 + libretroshare/src/turtle/rsturtleitem.h | 1 + 5 files changed, 144 insertions(+), 13 deletions(-) diff --git a/libretroshare/src/crypto/chacha20.cpp b/libretroshare/src/crypto/chacha20.cpp index b2b61e182..b49948457 100644 --- a/libretroshare/src/crypto/chacha20.cpp +++ b/libretroshare/src/crypto/chacha20.cpp @@ -307,18 +307,18 @@ static void print(const chacha20_state& s) static void add(chacha20_state& s,const chacha20_state& t) { for(uint32_t i=0;i<16;++i) s.c[i] += t.c[i] ; } -static uint8_t read16bits(char s) -{ - if(s >= '0' && s <= '9') - return s - '0' ; - else if(s >= 'a' && s <= 'f') - return s - 'a' + 10 ; - else if(s >= 'A' && s <= 'F') - return s - 'A' + 10 ; - else - throw std::runtime_error("Not an hex string!") ; -} - +// static uint8_t read16bits(char s) +// { +// if(s >= '0' && s <= '9') +// return s - '0' ; +// else if(s >= 'a' && s <= 'f') +// return s - 'a' + 10 ; +// else if(s >= 'A' && s <= 'F') +// return s - 'A' + 10 ; +// else +// throw std::runtime_error("Not an hex string!") ; +// } +// // static uint256_32 create_256bit_int(const std::string& s) // { // uint256_32 r(0,0,0,0,0,0,0,0) ; @@ -431,6 +431,12 @@ void poly1305_tag(uint8_t key[32],uint8_t *message,uint32_t size,uint8_t tag[16] tag[12] = (acc.b[3] >> 0) & 0xff ; tag[13] = (acc.b[3] >> 8) & 0xff ; tag[14] = (acc.b[3] >>16) & 0xff ; tag[15] = (acc.b[3] >>24) & 0xff ; } +void AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint32_t data_size,uint8_t *aad,uint32_t aad_size,uint8_t tag[16]) +{ +#warning this part is not implemented yet. + memset(tag,0xff,16) ; +} + void perform_tests() { std::cerr << "Testing Chacha20" << std::endl; diff --git a/libretroshare/src/crypto/chacha20.h b/libretroshare/src/crypto/chacha20.h index 77f266193..bc6f86a03 100644 --- a/libretroshare/src/crypto/chacha20.h +++ b/libretroshare/src/crypto/chacha20.h @@ -62,7 +62,18 @@ namespace librs * \param size size of the data * \param tag generated poly1305 tag. */ - static void AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint32_t data_size,uint8_t *aad,uint8_t *aad_size,uint8_t tag[16]) ; + static void AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint32_t data_size,uint8_t *aad,uint32_t aad_size,uint8_t tag[16]) ; + + /*! + * \brief constant_time_memcmp + * Provides a constant time comparison of two memory chunks. The implementation comes from the FreeBSD implementation. + * + * \param m1 memory block 1 + * \param m2 memory block 2 + * \param size common size of m1 and m2 + * \return + */ + static bool constant_time_memcmp(const uint8_t *m1,const uint8_t *m2,uint32_t size) ; /*! * \brief perform_tests diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 832530ade..382dbb4a9 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -27,6 +27,8 @@ #include #include "util/rsdebug.h" #include "util/rsdir.h" +#include "util/rsprint.h" +#include "crypto/chacha20.h" #include "retroshare/rstypes.h" #include "retroshare/rspeers.h" const int ftserverzone = 29539; @@ -984,6 +986,113 @@ bool ftServer::sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t return true; } +// Encrypts the given item using aead-chacha20-poly1305 +// +// The format is the following +// +// [encryption format] [random initialization vector] [encrypted data size] [encrypted data] [authentication tag] +// 4 bytes 12 bytes 4 bytes variable 16 bytes +// +// +-------------------- authenticated data part ----------------------+ +// +// +// Encryption format: +// ae ad 00 01 : encryption using AEAD, format 00, version 01 +// +// + +void ftServer::deriveEncryptionKey(const RsFileHash& hash, uint8_t *key) +{ + // The encryption key is simply the 256 hash of the + SHA256_CTX sha_ctx ; + + if(SHA256_DIGEST_LENGTH != 32) + throw std::runtime_error("Warning: can't compute Sha1Sum with sum size != 32") ; + + SHA256_Init(&sha_ctx); + SHA256_Update(&sha_ctx, hash.toByteArray(), hash.SIZE_IN_BYTES); + SHA256_Final (key, &sha_ctx); +} + +bool ftServer::encryptItem(RsTurtleGenericTunnelItem *clear_item,const RsFileHash& hash,RsTurtleGenericDataItem *& encrypted_item) +{ + static const uint32_t ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE = 12 ; + static const uint32_t ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE = 16 ; + static const uint32_t ENCRYPTED_FT_HEADER_SIZE = 4 ; + static const uint32_t ENCRYPTED_FT_EDATA_SIZE = 4 ; + + uint8_t initialization_vector[ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE] ; + + RSRandom::random_bytes(initialization_vector,ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE) ; + + std::cerr << "ftServer::Encrypting ft item." << std::endl; + std::cerr << " random nonce : " << RsUtil::BinToHex(initialization_vector,ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE) << std::endl; + + uint32_t total_data_size = ENCRYPTED_FT_HEADER_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + clear_item->serial_size() + ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE ; + + std::cerr << " clear part size : " << clear_item->serial_size() << std::endl; + std::cerr << " total item size : " << total_data_size << std::endl; + + encrypted_item = new RsTurtleGenericDataItem ; + encrypted_item->data_bytes = rs_malloc( total_data_size ) ; + encrypted_item->data_size = total_data_size ; + + if(encrypted_item->data_bytes == NULL) + return false ; + + uint8_t *edata = (uint8_t*)encrypted_item->data_bytes ; + uint32_t edata_size = clear_item->serial_size() ; + uint32_t offset = 0; + + edata[0] = 0xae ; + edata[1] = 0xad ; + edata[2] = 0x00 ; + edata[3] = 0x01 ; + + offset += ENCRYPTED_FT_HEADER_SIZE; + uint32_t aad_offset = offset ; + uint32_t aad_size = ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_EDATA_SIZE ; + + memcpy(&edata[offset], initialization_vector, ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE) ; + offset += ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE ; + + edata[offset+0] = (edata_size >> 0) & 0xff ; + edata[offset+1] = (edata_size >> 8) & 0xff ; + edata[offset+2] = (edata_size >> 16) & 0xff ; + edata[offset+3] = (edata_size >> 24) & 0xff ; + + offset += ENCRYPTED_FT_EDATA_SIZE ; + + uint32_t ser_size = (uint32_t)((int)total_data_size - (int)offset); + clear_item->serialize(&edata[offset], ser_size); + + std::cerr << " clear item : " << RsUtil::BinToHex(&edata[offset],std::min(50,(int)total_data_size-(int)offset)) << "(...)" << std::endl; + + uint32_t clear_item_offset = offset ; + offset += edata_size ; + + uint32_t authentication_tag_offset = offset ; + assert(ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE + offset == total_data_size) ; + + uint8_t encryption_key[32] ; + deriveEncryptionKey(hash,encryption_key) ; + + librs::crypto::AEAD_chacha20_poly1305(encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset]) ; + + std::cerr << " encryption key : " << RsUtil::BinToHex(encryption_key,32) << std::endl; + std::cerr << " authen. tag : " << RsUtil::BinToHex(&edata[authentication_tag_offset],ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE) << std::endl; + std::cerr << " final item : " << RsUtil::BinToHex(&edata[0],std::min(50u,total_data_size)) << "(...)" << std::endl; + + return true ; +} + +// Decrypts the given item using aead-chacha20-poly1305 + +bool ftServer::decryptItem(RsTurtleGenericTunnelItem *encrypted_item,const RsFileHash& hash,RsTurtleGenericDataItem *& decrypted_item) +{ + decrypted_item = NULL ; +} + // Dont delete the item. The client (p3turtle) is doing it after calling this. // void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i, diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index c5d1d23eb..97e54ffd6 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -224,6 +224,10 @@ public: virtual bool sendSingleChunkCRCRequest(const RsPeerId& peer_id,const RsFileHash& hash,uint32_t chunk_number) ; virtual bool sendSingleChunkCRC(const RsPeerId& peer_id,const RsFileHash& hash,uint32_t chunk_number,const Sha1CheckSum& crc) ; + static void deriveEncryptionKey(const RsFileHash& hash, uint8_t *key); + static bool encryptItem(RsTurtleGenericTunnelItem *clear_item,const RsFileHash& hash,RsTurtleGenericDataItem *& encrypted_item); + static bool decryptItem(RsTurtleGenericTunnelItem *encrypted_item,const RsFileHash& hash,RsTurtleGenericDataItem *& decrypted_item); + /*************** Internal Transfer Fns *************************/ virtual int tick(); diff --git a/libretroshare/src/turtle/rsturtleitem.h b/libretroshare/src/turtle/rsturtleitem.h index 11e1969e7..db210b49c 100644 --- a/libretroshare/src/turtle/rsturtleitem.h +++ b/libretroshare/src/turtle/rsturtleitem.h @@ -35,6 +35,7 @@ class RsTurtleItem: public RsItem public: RsTurtleItem(uint8_t turtle_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_TURTLE,turtle_subtype) {} +#warning we need some consts here virtual bool serialize(void *data,uint32_t& size) = 0 ; // Isn't it better that items can serialize themselves ? virtual uint32_t serial_size() = 0 ; // deserialise is handled using a constructor From 9d324066697560d9d24ed43c744f19e148bc0b84 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Wed, 19 Oct 2016 22:49:51 +0200 Subject: [PATCH 03/52] added ft decryption routine --- libretroshare/src/crypto/chacha20.cpp | 35 +++++++++------ libretroshare/src/crypto/chacha20.h | 14 +++--- libretroshare/src/ft/ftserver.cc | 64 ++++++++++++++++++++++++--- libretroshare/src/ft/ftserver.h | 5 ++- 4 files changed, 90 insertions(+), 28 deletions(-) diff --git a/libretroshare/src/crypto/chacha20.cpp b/libretroshare/src/crypto/chacha20.cpp index b49948457..6ab45d623 100644 --- a/libretroshare/src/crypto/chacha20.cpp +++ b/libretroshare/src/crypto/chacha20.cpp @@ -28,10 +28,13 @@ #include #include #include +#include #include #include +#pragma once + #define rotl(x,n) { x = (x << n) | (x >> (-n & 31)) ;} namespace librs { @@ -431,10 +434,16 @@ void poly1305_tag(uint8_t key[32],uint8_t *message,uint32_t size,uint8_t tag[16] tag[12] = (acc.b[3] >> 0) & 0xff ; tag[13] = (acc.b[3] >> 8) & 0xff ; tag[14] = (acc.b[3] >>16) & 0xff ; tag[15] = (acc.b[3] >>24) & 0xff ; } -void AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint32_t data_size,uint8_t *aad,uint32_t aad_size,uint8_t tag[16]) +bool AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint32_t data_size,uint8_t *aad,uint32_t aad_size,uint8_t tag[16]) { #warning this part is not implemented yet. memset(tag,0xff,16) ; + return false; +} + +bool constant_time_memory_compare(const uint8_t *m1,const uint8_t *m2,uint32_t size) +{ + return !CRYPTO_memcmp(m1,m2,size) ; } void perform_tests() @@ -658,7 +667,7 @@ void perform_tests() uint8_t test_tag[16] = { 0xa8,0x06,0x1d,0xc1,0x30,0x51,0x36,0xc6,0xc2,0x2b,0x8b,0xaf,0x0c,0x01,0x27,0xa9 }; - assert(!memcmp(tag,test_tag,16)) ; + assert(constant_time_memory_compare(tag,test_tag,16)) ; } std::cerr << " RFC7539 poly1305 test vector #001 OK" << std::endl; @@ -676,7 +685,7 @@ void perform_tests() uint8_t test_tag[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; - assert(!memcmp(tag,test_tag,16)) ; + assert(constant_time_memory_compare(tag,test_tag,16)) ; } std::cerr << " RFC7539 poly1305 test vector #002 OK" << std::endl; @@ -695,7 +704,7 @@ void perform_tests() uint8_t test_tag[16] = { 0x36,0xe5,0xf6,0xb5,0xc5,0xe0,0x60,0x70,0xf0,0xef,0xca,0x96,0x22,0x7a,0x86,0x3e }; - assert(!memcmp(tag,test_tag,16)) ; + assert(constant_time_memory_compare(tag,test_tag,16)) ; } std::cerr << " RFC7539 poly1305 test vector #003 OK" << std::endl; @@ -714,7 +723,7 @@ void perform_tests() uint8_t test_tag[16] = { 0xf3,0x47,0x7e,0x7c,0xd9,0x54,0x17,0xaf,0x89,0xa6,0xb8,0x79,0x4c,0x31,0x0c,0xf0 } ; - assert(!memcmp(tag,test_tag,16)) ; + assert(constant_time_memory_compare(tag,test_tag,16)) ; } std::cerr << " RFC7539 poly1305 test vector #004 OK" << std::endl; @@ -731,7 +740,7 @@ void perform_tests() uint8_t test_tag[16] = { 0x45,0x41,0x66,0x9a,0x7e,0xaa,0xee,0x61,0xe7,0x08,0xdc,0x7c,0xbc,0xc5,0xeb,0x62 } ; - assert(!memcmp(tag,test_tag,16)) ; + assert(constant_time_memory_compare(tag,test_tag,16)) ; } std::cerr << " RFC7539 poly1305 test vector #005 OK" << std::endl; @@ -749,7 +758,7 @@ void perform_tests() uint8_t test_tag[16] = { 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } ; - assert(!memcmp(tag,test_tag,16)) ; + assert(constant_time_memory_compare(tag,test_tag,16)) ; } std::cerr << " RFC7539 poly1305 test vector #006 OK" << std::endl; @@ -767,7 +776,7 @@ void perform_tests() uint8_t test_tag[16] = { 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } ; - assert(!memcmp(tag,test_tag,16)) ; + assert(constant_time_memory_compare(tag,test_tag,16)) ; } std::cerr << " RFC7539 poly1305 test vector #007 OK" << std::endl; @@ -786,7 +795,7 @@ void perform_tests() uint8_t test_tag[16] = { 0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } ; - assert(!memcmp(tag,test_tag,16)) ; + assert(constant_time_memory_compare(tag,test_tag,16)) ; } std::cerr << " RFC7539 poly1305 test vector #008 OK" << std::endl; @@ -805,7 +814,7 @@ void perform_tests() uint8_t test_tag[16] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } ; - assert(!memcmp(tag,test_tag,16)) ; + assert(constant_time_memory_compare(tag,test_tag,16)) ; } std::cerr << " RFC7539 poly1305 test vector #009 OK" << std::endl; @@ -822,7 +831,7 @@ void perform_tests() uint8_t test_tag[16] = { 0xfa,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff } ; - assert(!memcmp(tag,test_tag,16)) ; + assert(constant_time_memory_compare(tag,test_tag,16)) ; } std::cerr << " RFC7539 poly1305 test vector #010 OK" << std::endl; @@ -843,7 +852,7 @@ void perform_tests() uint8_t test_tag[16] = { 0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x55,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } ; - assert(!memcmp(tag,test_tag,16)) ; + assert(constant_time_memory_compare(tag,test_tag,16)) ; } std::cerr << " RFC7539 poly1305 test vector #011 OK" << std::endl; @@ -863,7 +872,7 @@ void perform_tests() uint8_t test_tag[16] = { 0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } ; - assert(!memcmp(tag,test_tag,16)) ; + assert(constant_time_memory_compare(tag,test_tag,16)) ; } } diff --git a/libretroshare/src/crypto/chacha20.h b/libretroshare/src/crypto/chacha20.h index bc6f86a03..a8ed00176 100644 --- a/libretroshare/src/crypto/chacha20.h +++ b/libretroshare/src/crypto/chacha20.h @@ -37,7 +37,7 @@ namespace librs * \param data data that gets encrypted/decrypted in place * \param size size of the data. */ - static void chacha20_encrypt(uint8_t key[32], uint32_t block_counter, uint8_t nonce[12], uint8_t *data, uint32_t size) ; + void chacha20_encrypt(uint8_t key[32], uint32_t block_counter, uint8_t nonce[12], uint8_t *data, uint32_t size) ; /*! * \brief poly1305_tag @@ -48,7 +48,7 @@ namespace librs * \param tag place where the tag is stored. */ - static void poly1305_tag(uint8_t key[32],uint8_t *message,uint32_t size,uint8_t tag[16]); + void poly1305_tag(uint8_t key[32],uint8_t *message,uint32_t size,uint8_t tag[16]); /*! * \brief AEAD_chacha20_poly1305 @@ -62,24 +62,26 @@ namespace librs * \param size size of the data * \param tag generated poly1305 tag. */ - static void AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint32_t data_size,uint8_t *aad,uint32_t aad_size,uint8_t tag[16]) ; + bool AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint32_t data_size,uint8_t *aad,uint32_t aad_size,uint8_t tag[16]) ; /*! * \brief constant_time_memcmp - * Provides a constant time comparison of two memory chunks. The implementation comes from the FreeBSD implementation. + * Provides a constant time comparison of two memory chunks. Calls CRYPTO_memcmp. * * \param m1 memory block 1 * \param m2 memory block 2 * \param size common size of m1 and m2 * \return + * false if the two chunks are different + * true if the two chunks are different */ - static bool constant_time_memcmp(const uint8_t *m1,const uint8_t *m2,uint32_t size) ; + bool constant_time_memory_compare(const uint8_t *m1,const uint8_t *m2,uint32_t size) ; /*! * \brief perform_tests * Tests all methods in this class, using the tests supplied in RFC7539 */ - static void perform_tests() ; + void perform_tests() ; } } diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 382dbb4a9..aa57ac38f 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -1014,13 +1014,13 @@ void ftServer::deriveEncryptionKey(const RsFileHash& hash, uint8_t *key) SHA256_Final (key, &sha_ctx); } +static const uint32_t ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE = 12 ; +static const uint32_t ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE = 16 ; +static const uint32_t ENCRYPTED_FT_HEADER_SIZE = 4 ; +static const uint32_t ENCRYPTED_FT_EDATA_SIZE = 4 ; + bool ftServer::encryptItem(RsTurtleGenericTunnelItem *clear_item,const RsFileHash& hash,RsTurtleGenericDataItem *& encrypted_item) { - static const uint32_t ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE = 12 ; - static const uint32_t ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE = 16 ; - static const uint32_t ENCRYPTED_FT_HEADER_SIZE = 4 ; - static const uint32_t ENCRYPTED_FT_EDATA_SIZE = 4 ; - uint8_t initialization_vector[ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE] ; RSRandom::random_bytes(initialization_vector,ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE) ; @@ -1088,9 +1088,59 @@ bool ftServer::encryptItem(RsTurtleGenericTunnelItem *clear_item,const RsFileHas // Decrypts the given item using aead-chacha20-poly1305 -bool ftServer::decryptItem(RsTurtleGenericTunnelItem *encrypted_item,const RsFileHash& hash,RsTurtleGenericDataItem *& decrypted_item) +bool ftServer::decryptItem(RsTurtleGenericDataItem *encrypted_item,const RsFileHash& hash,RsTurtleGenericTunnelItem *& decrypted_item) { - decrypted_item = NULL ; + uint8_t encryption_key[32] ; + deriveEncryptionKey(hash,encryption_key) ; + + uint8_t *edata = (uint8_t*)encrypted_item->data_bytes ; + uint32_t offset = 0; + + if(encrypted_item->data_size < ENCRYPTED_FT_HEADER_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_EDATA_SIZE) return false ; + + if(edata[0] != 0xae) return false ; + if(edata[1] != 0xad) return false ; + if(edata[2] != 0x00) return false ; + if(edata[3] != 0x01) return false ; + + offset += ENCRYPTED_FT_HEADER_SIZE ; + uint32_t aad_offset = offset ; + uint32_t aad_size = ENCRYPTED_FT_EDATA_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE ; + + uint8_t *initialization_vector = &edata[offset] ; + + std::cerr << "ftServer::decrypting ft item." << std::endl; + std::cerr << " item data : " << RsUtil::BinToHex(edata,std::min(50u,encrypted_item->data_size)) << "(...)" << std::endl; + std::cerr << " hash : " << hash << std::endl; + std::cerr << " encryption key : " << RsUtil::BinToHex(encryption_key,32) << std::endl; + std::cerr << " random nonce : " << RsUtil::BinToHex(initialization_vector,ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE) << std::endl; + + offset += ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE ; + + uint32_t edata_size = 0 ; + edata_size += ((uint32_t)edata[offset+0]) << 0 ; + edata_size += ((uint32_t)edata[offset+1]) << 8 ; + edata_size += ((uint32_t)edata[offset+2]) << 16 ; + edata_size += ((uint32_t)edata[offset+3]) << 24 ; + + offset += ENCRYPTED_FT_EDATA_SIZE ; + uint32_t clear_item_offset = offset ; + + uint32_t authentication_tag_offset = offset + edata_size ; + std::cerr << " authen. tag : " << RsUtil::BinToHex(&edata[authentication_tag_offset],ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE) << std::endl; + + if(!librs::crypto::AEAD_chacha20_poly1305(encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset])) + return false; + + std::cerr << " authen. result : ok" << std::endl; + std::cerr << " decrypted daya : ok" << RsUtil::BinToHex(&edata[clear_item_offset],std::min(50u,edata_size)) << "(...)" << std::endl; + + decrypted_item = deserialiseItem(&edata[clear_item_offset],edata_size) ; + + if(decrypted_item == NULL) + return false ; + + return true ; } // Dont delete the item. The client (p3turtle) is doing it after calling this. diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index 97e54ffd6..4579c21ec 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -225,8 +225,9 @@ public: virtual bool sendSingleChunkCRC(const RsPeerId& peer_id,const RsFileHash& hash,uint32_t chunk_number,const Sha1CheckSum& crc) ; static void deriveEncryptionKey(const RsFileHash& hash, uint8_t *key); - static bool encryptItem(RsTurtleGenericTunnelItem *clear_item,const RsFileHash& hash,RsTurtleGenericDataItem *& encrypted_item); - static bool decryptItem(RsTurtleGenericTunnelItem *encrypted_item,const RsFileHash& hash,RsTurtleGenericDataItem *& decrypted_item); + + bool encryptItem(RsTurtleGenericTunnelItem *clear_item,const RsFileHash& hash,RsTurtleGenericDataItem *& encrypted_item); + bool decryptItem(RsTurtleGenericDataItem *encrypted_item, const RsFileHash& hash, RsTurtleGenericTunnelItem *&decrypted_item); /*************** Internal Transfer Fns *************************/ virtual int tick(); From 2d72b881307d7a3a6259a6ec173e877f4671ddbd Mon Sep 17 00:00:00 2001 From: mr-alice Date: Mon, 24 Oct 2016 15:59:34 +0200 Subject: [PATCH 04/52] added code for AEAD construction --- libretroshare/src/crypto/chacha20.cpp | 122 +++++++++++++++++++++----- libretroshare/src/crypto/chacha20.h | 8 +- libretroshare/src/ft/ftserver.cc | 4 +- 3 files changed, 109 insertions(+), 25 deletions(-) diff --git a/libretroshare/src/crypto/chacha20.cpp b/libretroshare/src/crypto/chacha20.cpp index 6ab45d623..26ee4a924 100644 --- a/libretroshare/src/crypto/chacha20.cpp +++ b/libretroshare/src/crypto/chacha20.cpp @@ -387,27 +387,40 @@ void chacha20_encrypt(uint8_t key[32], uint32_t block_counter, uint8_t nonce[12] } } -void poly1305_tag(uint8_t key[32],uint8_t *message,uint32_t size,uint8_t tag[16]) +struct poly1305_state { - uint256_32 r( 0,0,0,0, + uint256_32 r ; + uint256_32 s ; + uint256_32 p ; + uint256_32 a ; +}; + +static void poly1305_init(poly1305_state& s,uint8_t key[32]) +{ + s.r = uint256_32( 0,0,0,0, ((uint32_t)key[12] << 0) + ((uint32_t)key[13] << 8) + ((uint32_t)key[14] << 16) + ((uint32_t)key[15] << 24), ((uint32_t)key[ 8] << 0) + ((uint32_t)key[ 9] << 8) + ((uint32_t)key[10] << 16) + ((uint32_t)key[11] << 24), ((uint32_t)key[ 4] << 0) + ((uint32_t)key[ 5] << 8) + ((uint32_t)key[ 6] << 16) + ((uint32_t)key[ 7] << 24), ((uint32_t)key[ 0] << 0) + ((uint32_t)key[ 1] << 8) + ((uint32_t)key[ 2] << 16) + ((uint32_t)key[ 3] << 24) ); - r.poly1305clamp(); + s.r.poly1305clamp(); - uint256_32 s( 0,0,0,0, + s.s = uint256_32( 0,0,0,0, ((uint32_t)key[28] << 0) + ((uint32_t)key[29] << 8) + ((uint32_t)key[30] << 16) + ((uint32_t)key[31] << 24), ((uint32_t)key[24] << 0) + ((uint32_t)key[25] << 8) + ((uint32_t)key[26] << 16) + ((uint32_t)key[27] << 24), ((uint32_t)key[20] << 0) + ((uint32_t)key[21] << 8) + ((uint32_t)key[22] << 16) + ((uint32_t)key[23] << 24), ((uint32_t)key[16] << 0) + ((uint32_t)key[17] << 8) + ((uint32_t)key[18] << 16) + ((uint32_t)key[19] << 24) ); - uint256_32 p(0,0,0,0x3,0xffffffff,0xffffffff,0xffffffff,0xfffffffb) ; - uint256_32 acc(0,0,0, 0, 0, 0, 0, 0) ; + s.p = uint256_32(0,0,0,0x3,0xffffffff,0xffffffff,0xffffffff,0xfffffffb) ; + s.a = uint256_32(0,0,0, 0, 0, 0, 0, 0) ; +} +// Warning: each call will automatically *pad* the data to a multiple of 16 bytes. +// +static void poly1305_add(poly1305_state& s,uint8_t *message,uint32_t size) +{ for(uint32_t i=0;i<(size+15)/16;++i) { uint256_32 block ; @@ -418,27 +431,44 @@ void poly1305_tag(uint8_t key[32],uint8_t *message,uint32_t size,uint8_t tag[16] block.b[j/4] += 0x01 << (8*(j& 0x3)); - acc += block ; - acc *= r ; + s.a += block ; + s.a *= s.r ; uint256_32 q,rst; - quotient(acc,p,q,rst) ; - acc = rst ; + quotient(s.a,s.p,q,rst) ; + s.a = rst ; } - - acc += s ; - - tag[ 0] = (acc.b[0] >> 0) & 0xff ; tag[ 1] = (acc.b[0] >> 8) & 0xff ; tag[ 2] = (acc.b[0] >>16) & 0xff ; tag[ 3] = (acc.b[0] >>24) & 0xff ; - tag[ 4] = (acc.b[1] >> 0) & 0xff ; tag[ 5] = (acc.b[1] >> 8) & 0xff ; tag[ 6] = (acc.b[1] >>16) & 0xff ; tag[ 7] = (acc.b[1] >>24) & 0xff ; - tag[ 8] = (acc.b[2] >> 0) & 0xff ; tag[ 9] = (acc.b[2] >> 8) & 0xff ; tag[10] = (acc.b[2] >>16) & 0xff ; tag[11] = (acc.b[2] >>24) & 0xff ; - tag[12] = (acc.b[3] >> 0) & 0xff ; tag[13] = (acc.b[3] >> 8) & 0xff ; tag[14] = (acc.b[3] >>16) & 0xff ; tag[15] = (acc.b[3] >>24) & 0xff ; } -bool AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint32_t data_size,uint8_t *aad,uint32_t aad_size,uint8_t tag[16]) +static void poly1305_finish(poly1305_state& s,uint8_t tag[16]) { -#warning this part is not implemented yet. - memset(tag,0xff,16) ; - return false; + s.a += s.s ; + + tag[ 0] = (s.a.b[0] >> 0) & 0xff ; tag[ 1] = (s.a.b[0] >> 8) & 0xff ; tag[ 2] = (s.a.b[0] >>16) & 0xff ; tag[ 3] = (s.a.b[0] >>24) & 0xff ; + tag[ 4] = (s.a.b[1] >> 0) & 0xff ; tag[ 5] = (s.a.b[1] >> 8) & 0xff ; tag[ 6] = (s.a.b[1] >>16) & 0xff ; tag[ 7] = (s.a.b[1] >>24) & 0xff ; + tag[ 8] = (s.a.b[2] >> 0) & 0xff ; tag[ 9] = (s.a.b[2] >> 8) & 0xff ; tag[10] = (s.a.b[2] >>16) & 0xff ; tag[11] = (s.a.b[2] >>24) & 0xff ; + tag[12] = (s.a.b[3] >> 0) & 0xff ; tag[13] = (s.a.b[3] >> 8) & 0xff ; tag[14] = (s.a.b[3] >>16) & 0xff ; tag[15] = (s.a.b[3] >>24) & 0xff ; +} + +void poly1305_tag(uint8_t key[32],uint8_t *message,uint32_t size,uint8_t tag[16]) +{ + poly1305_state s; + + poly1305_init (s,key); + poly1305_add (s,message,size); + poly1305_finish(s,tag); +} + +static void poly1305_key_gen(uint8_t key[32], uint8_t nonce[12], uint8_t generated_key[32]) +{ + uint32_t counter = 0 ; + + chacha20_state s(key,counter,nonce); + apply_20_rounds(s) ; + + for(uint32_t k=0;k<16;++k) + for(uint32_t i=0;i<4;++i) + generated_key[k*4 + i] = (s.c[k] >> 8*i) & 0xff ; } bool constant_time_memory_compare(const uint8_t *m1,const uint8_t *m2,uint32_t size) @@ -446,6 +476,56 @@ bool constant_time_memory_compare(const uint8_t *m1,const uint8_t *m2,uint32_t s return !CRYPTO_memcmp(m1,m2,size) ; } +bool AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint32_t data_size,uint8_t *aad,uint32_t aad_size,uint8_t tag[16],bool encrypt) +{ + // encrypt + tag. See RFC7539-2.8 + + uint8_t session_key[32]; + poly1305_key_gen(key,nonce,session_key); + + uint8_t lengths_vector[16] ; + for(uint32_t i=0;i<8;++i) + { + lengths_vector[0+i] = ( aad_size >> i) & 0xff ; + lengths_vector[8+i] = (data_size >> i) & 0xff ; + } + + if(encrypt) + { + chacha20_encrypt(session_key,1,nonce,data,data_size); + + poly1305_state pls ; + + poly1305_init(pls,session_key); + + poly1305_add(pls,aad,aad_size); // add and pad the aad + poly1305_add(pls,data,data_size); // add and pad the cipher text + poly1305_add(pls,lengths_vector,16); // add the lengths + + poly1305_finish(pls,tag); + return true ; + } + else + { + poly1305_state pls ; + uint8_t computed_tag[16]; + + poly1305_init(pls,session_key); + + poly1305_add(pls,aad,aad_size); // add and pad the aad + poly1305_add(pls,data,data_size); // add and pad the cipher text + poly1305_add(pls,lengths_vector,16); // add the lengths + + poly1305_finish(pls,computed_tag); + + // decrypt + + chacha20_encrypt(session_key,1,nonce,data,data_size); + + return constant_time_memory_compare(tag,computed_tag,16) ; + } +} + void perform_tests() { std::cerr << "Testing Chacha20" << std::endl; diff --git a/libretroshare/src/crypto/chacha20.h b/libretroshare/src/crypto/chacha20.h index a8ed00176..361e2743f 100644 --- a/libretroshare/src/crypto/chacha20.h +++ b/libretroshare/src/crypto/chacha20.h @@ -57,12 +57,16 @@ namespace librs * 16-padded AAD (additional authenticated data) and its size, authenticated using poly1305. * * \param key key that is used to derive a one time secret key for poly1305 and that is also used to encrypt the data - * \param nonce nonce. *Should be unique* in order to make the ply1305 key unique. + * \param nonce nonce. *Should be unique* in order to make the poly1305 key unique. * \param data data that is encrypted. * \param size size of the data * \param tag generated poly1305 tag. + * \param encrypt true to encrypt, false to decrypt and check the tag. + * \return + * always true for encryption. + * authentication result for decryption. data is *always* xored to the cipher stream whatever the authentication result is. */ - bool AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint32_t data_size,uint8_t *aad,uint32_t aad_size,uint8_t tag[16]) ; + bool AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint32_t data_size,uint8_t *aad,uint32_t aad_size,uint8_t tag[16],bool encrypt_or_decrypt) ; /*! * \brief constant_time_memcmp diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index aa57ac38f..b80aa51a2 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -1077,7 +1077,7 @@ bool ftServer::encryptItem(RsTurtleGenericTunnelItem *clear_item,const RsFileHas uint8_t encryption_key[32] ; deriveEncryptionKey(hash,encryption_key) ; - librs::crypto::AEAD_chacha20_poly1305(encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset]) ; + librs::crypto::AEAD_chacha20_poly1305(encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset],true) ; std::cerr << " encryption key : " << RsUtil::BinToHex(encryption_key,32) << std::endl; std::cerr << " authen. tag : " << RsUtil::BinToHex(&edata[authentication_tag_offset],ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE) << std::endl; @@ -1129,7 +1129,7 @@ bool ftServer::decryptItem(RsTurtleGenericDataItem *encrypted_item,const RsFileH uint32_t authentication_tag_offset = offset + edata_size ; std::cerr << " authen. tag : " << RsUtil::BinToHex(&edata[authentication_tag_offset],ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE) << std::endl; - if(!librs::crypto::AEAD_chacha20_poly1305(encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset])) + if(!librs::crypto::AEAD_chacha20_poly1305(encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset],false)) return false; std::cerr << " authen. result : ok" << std::endl; From 0387a28e780bf53f07dc3aefdc019eb29d54e2ea Mon Sep 17 00:00:00 2001 From: mr-alice Date: Tue, 25 Oct 2016 00:08:27 +0200 Subject: [PATCH 05/52] added methods to get files from hash(hash) in directory_storage and ftServer --- libretroshare/src/crypto/chacha20.cpp | 2 + .../src/file_sharing/dir_hierarchy.cc | 13 +-- .../src/file_sharing/dir_hierarchy.h | 2 +- .../src/file_sharing/directory_storage.cc | 5 +- .../src/file_sharing/directory_storage.h | 2 +- libretroshare/src/file_sharing/p3filelists.cc | 14 +-- libretroshare/src/ft/ftserver.cc | 85 ++++++++++++++++--- libretroshare/src/ft/ftserver.h | 16 ++++ libretroshare/src/retroshare/rsfiles.h | 27 +++--- 9 files changed, 122 insertions(+), 44 deletions(-) diff --git a/libretroshare/src/crypto/chacha20.cpp b/libretroshare/src/crypto/chacha20.cpp index 26ee4a924..24e810283 100644 --- a/libretroshare/src/crypto/chacha20.cpp +++ b/libretroshare/src/crypto/chacha20.cpp @@ -33,6 +33,8 @@ #include #include +#include "crypto/chacha20.h" + #pragma once #define rotl(x,n) { x = (x << n) | (x >> (-n & 31)) ;} diff --git a/libretroshare/src/file_sharing/dir_hierarchy.cc b/libretroshare/src/file_sharing/dir_hierarchy.cc index a697fa120..f5c0dbeb4 100644 --- a/libretroshare/src/file_sharing/dir_hierarchy.cc +++ b/libretroshare/src/file_sharing/dir_hierarchy.cc @@ -661,18 +661,9 @@ DirectoryStorage::EntryIndex InternalFileHierarchyStorage::getSubDirIndex(Direct return static_cast(mNodes[parent_index])->subdirs[dir_tab_index]; } -bool InternalFileHierarchyStorage::searchHash(const RsFileHash& hash,std::list& results) +bool InternalFileHierarchyStorage::searchHash(const RsFileHash& hash,DirectoryStorage::EntryIndex& result) { - DirectoryStorage::EntryIndex indx ; - - if(getIndexFromFileHash(hash,indx)) - { - results.clear(); - results.push_back(indx) ; - return true ; - } - else - return false; + return getIndexFromFileHash(hash,result); } class DirectoryStorageExprFileEntry: public RsRegularExpression::ExpFileEntry diff --git a/libretroshare/src/file_sharing/dir_hierarchy.h b/libretroshare/src/file_sharing/dir_hierarchy.h index fe937fac9..dd1454b91 100644 --- a/libretroshare/src/file_sharing/dir_hierarchy.h +++ b/libretroshare/src/file_sharing/dir_hierarchy.h @@ -142,7 +142,7 @@ public: // search. SearchHash is logarithmic. The other two are linear. - bool searchHash(const RsFileHash& hash,std::list& results); + bool searchHash(const RsFileHash& hash, DirectoryStorage::EntryIndex &result); int searchBoolExp(RsRegularExpression::Expression * exp, std::list &results) const ; int searchTerms(const std::list& terms, std::list &results) const ; // does a logical OR between items of the list of terms diff --git a/libretroshare/src/file_sharing/directory_storage.cc b/libretroshare/src/file_sharing/directory_storage.cc index 02c406c5d..9ec32487f 100644 --- a/libretroshare/src/file_sharing/directory_storage.cc +++ b/libretroshare/src/file_sharing/directory_storage.cc @@ -168,10 +168,11 @@ bool DirectoryStorage::updateHash(const EntryIndex& index,const RsFileHash& hash return mFileHierarchy->updateHash(index,hash); } -int DirectoryStorage::searchHash(const RsFileHash& hash, std::list &results) const +int DirectoryStorage::searchHash(const RsFileHash& hash, const RsFileHash& real_hash, EntryIndex& result) const { RS_STACK_MUTEX(mDirStorageMtx) ; - return mFileHierarchy->searchHash(hash,results); +#warning code needed here + return mFileHierarchy->searchHash(hash,result); } void DirectoryStorage::load(const std::string& local_file_name) diff --git a/libretroshare/src/file_sharing/directory_storage.h b/libretroshare/src/file_sharing/directory_storage.h index 2d8119445..653b1286d 100644 --- a/libretroshare/src/file_sharing/directory_storage.h +++ b/libretroshare/src/file_sharing/directory_storage.h @@ -53,7 +53,7 @@ class DirectoryStorage virtual int searchTerms(const std::list& terms, std::list &results) const ; virtual int searchBoolExp(RsRegularExpression::Expression * exp, std::list &results) const ; - virtual int searchHash(const RsFileHash& hash, std::list &results) const ; + virtual int searchHash(const RsFileHash& hash, const RsFileHash &real_hash, EntryIndex &results) const ; // gets/sets the various time stamps: // diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index e53bc8e9a..199641298 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -979,16 +979,20 @@ bool p3FileDatabase::search(const RsFileHash &hash, FileSearchFlags hintflags, F if(hintflags & RS_FILE_HINTS_LOCAL) { - std::list res; - mLocalSharedDirs->searchHash(hash,res) ; + RsFileHash real_hash ; + EntryIndex indx; - if(res.empty()) + if(!mLocalSharedDirs->searchHash(hash,real_hash,indx)) return false; - EntryIndex indx = *res.begin() ; // no need to report duplicates - mLocalSharedDirs->getFileInfo(indx,info) ; + if(!real_hash.isNull()) + { + info.hash = real_hash ; + info.transfer_info_flags |= RS_FILE_REQ_ENCRYPTED ; + } + return true; } diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index b80aa51a2..e5476f725 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -730,6 +730,31 @@ bool ftServer::shareDownloadDirectory(bool share) /********************** Data Flow **********************/ /***************************************************************/ +bool ftServer::sendTurtleItem(const RsPeerId& peerId,const RsFileHash& hash,RsTurtleGenericTunnelItem *item) +{ + // first, we look for the encrypted hash map +#warning code needed here + if(true) + { + // we don't encrypt + mTurtleRouter->sendTurtleData(peerId,item) ; + } + else + { + // we encrypt the item + + RsTurtleGenericDataItem *encrypted_item ; + + if(!encryptItem(item, hash, encrypted_item)) + return false ; + + delete item ; + + mTurtleRouter->sendTurtleData(peerId,encrypted_item) ; + } + return true ; +} + /* Client Send */ bool ftServer::sendDataRequest(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize) { @@ -743,7 +768,7 @@ bool ftServer::sendDataRequest(const RsPeerId& peerId, const RsFileHash& hash, u item->chunk_offset = offset ; item->chunk_size = chunksize ; - mTurtleRouter->sendTurtleData(peerId,item) ; + sendTurtleItem(peerId,hash,item) ; } else { @@ -776,8 +801,8 @@ bool ftServer::sendChunkMapRequest(const RsPeerId& peerId,const RsFileHash& hash if(mTurtleRouter->isTurtlePeer(peerId)) { RsTurtleFileMapRequestItem *item = new RsTurtleFileMapRequestItem ; - mTurtleRouter->sendTurtleData(peerId,item) ; - } + sendTurtleItem(peerId,hash,item) ; + } else { /* create a packet */ @@ -806,8 +831,8 @@ bool ftServer::sendChunkMap(const RsPeerId& peerId,const RsFileHash& hash,const { RsTurtleFileMapItem *item = new RsTurtleFileMapItem ; item->compressed_map = map ; - mTurtleRouter->sendTurtleData(peerId,item) ; - } + sendTurtleItem(peerId,hash,item) ; + } else { /* create a packet */ @@ -838,8 +863,8 @@ bool ftServer::sendSingleChunkCRCRequest(const RsPeerId& peerId,const RsFileHash RsTurtleChunkCrcRequestItem *item = new RsTurtleChunkCrcRequestItem; item->chunk_number = chunk_number ; - mTurtleRouter->sendTurtleData(peerId,item) ; - } + sendTurtleItem(peerId,hash,item) ; + } else { /* create a packet */ @@ -870,8 +895,8 @@ bool ftServer::sendSingleChunkCRC(const RsPeerId& peerId,const RsFileHash& hash, item->chunk_number = chunk_number ; item->check_sum = crc ; - mTurtleRouter->sendTurtleData(peerId,item) ; - } + sendTurtleItem(peerId,hash,item) ; + } else { /* create a packet */ @@ -941,8 +966,8 @@ bool ftServer::sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t } memcpy(item->chunk_data,&(((uint8_t *) data)[offset]),chunk) ; - mTurtleRouter->sendTurtleData(peerId,item) ; - } + sendTurtleItem(peerId,hash,item) ; + } else { RsFileTransferDataItem *rfd = new RsFileTransferDataItem(); @@ -1143,6 +1168,19 @@ bool ftServer::decryptItem(RsTurtleGenericDataItem *encrypted_item,const RsFileH return true ; } +bool ftServer::findRealHash(const RsFileHash& hash, RsFileHash& real_hash) +{ + std::map::const_iterator it = mEncryptedHashes.find(hash) ; + + if(it != mEncryptedHashes.end()) + { + real_hash = it->second ; + return true ; + } + else + return false ; +} + // Dont delete the item. The client (p3turtle) is doing it after calling this. // void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i, @@ -1150,6 +1188,31 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i, const RsPeerId& virtual_peer_id, RsTurtleGenericTunnelItem::Direction direction) { + if(i->PacketSubType() == RS_TURTLE_SUBTYPE_GENERIC_DATA) + { + std::cerr << "Received encrypted data item. Trying to decrypt" << std::endl; + + RsFileHash real_hash ; + + if(!findRealHash(hash,real_hash)) + { + std::cerr << "(EE) Cannot find real hash for encrypted data item with H(H(F))=" << hash << ". This is unexpected." << std::endl; + return ; + } + + RsTurtleGenericTunnelItem *decrypted_item ; + if(!decryptItem(dynamic_cast(i),real_hash,decrypted_item)) + { + std::cerr << "(EE) decryption error." << std::endl; + return ; + } + + receiveTurtleData(decrypted_item, real_hash, virtual_peer_id,direction) ; + + delete decrypted_item ; + return ; + } + switch(i->PacketSubType()) { case RS_TURTLE_SUBTYPE_FILE_REQUEST: diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index 4579c21ec..4f36aad91 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -242,6 +242,20 @@ protected: int handleIncoming() ; bool handleCacheData() ; + /*! + * \brief sendTurtleItem + * Sends the given item into a turtle tunnel, possibly encrypting it if the type of tunnel requires it, which is known from the hash itself. + * \param peerId Peer id to send to (this is a virtual peer id from turtle service) + * \param hash hash of the file. If the item needs to be encrypted + * \param item item to send. + * \return + * true if everything goes right + */ + bool sendTurtleItem(const RsPeerId& peerId,const RsFileHash& hash,RsTurtleGenericTunnelItem *item); + + // fnds out what is the real hash of encrypted hash hash + bool findRealHash(const RsFileHash& hash, RsFileHash& real_hash); + private: /**** INTERNAL FUNCTIONS ***/ @@ -266,6 +280,8 @@ private: std::string mConfigPath; std::string mDownloadPath; std::string mPartialsPath; + + std::map mEncryptedHashes ; // This map is such that sha1(it->second) = it->first }; diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index cd12396fb..b9f7a69be 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -63,26 +63,27 @@ const uint32_t RS_FILE_PEER_OFFLINE = 0x00002000; // Flags used when requesting info about transfers, mostly to filter out the result. // -const FileSearchFlags RS_FILE_HINTS_CACHE_deprecated ( 0x00000001 ); -const FileSearchFlags RS_FILE_HINTS_EXTRA ( 0x00000002 ); -const FileSearchFlags RS_FILE_HINTS_LOCAL ( 0x00000004 ); -const FileSearchFlags RS_FILE_HINTS_REMOTE ( 0x00000008 ); -const FileSearchFlags RS_FILE_HINTS_DOWNLOAD ( 0x00000010 ); -const FileSearchFlags RS_FILE_HINTS_UPLOAD ( 0x00000020 ); -const FileSearchFlags RS_FILE_HINTS_SPEC_ONLY ( 0x01000000 ); +const FileSearchFlags RS_FILE_HINTS_CACHE_deprecated ( 0x00000001 ); +const FileSearchFlags RS_FILE_HINTS_EXTRA ( 0x00000002 ); +const FileSearchFlags RS_FILE_HINTS_LOCAL ( 0x00000004 ); +const FileSearchFlags RS_FILE_HINTS_REMOTE ( 0x00000008 ); +const FileSearchFlags RS_FILE_HINTS_DOWNLOAD ( 0x00000010 ); +const FileSearchFlags RS_FILE_HINTS_UPLOAD ( 0x00000020 ); +const FileSearchFlags RS_FILE_HINTS_SPEC_ONLY ( 0x01000000 ); -const FileSearchFlags RS_FILE_HINTS_NETWORK_WIDE ( 0x00000080 );// anonymously shared over network -const FileSearchFlags RS_FILE_HINTS_BROWSABLE ( 0x00000100 );// browsable by friends -const FileSearchFlags RS_FILE_HINTS_PERMISSION_MASK ( 0x00000180 );// OR of the last two flags. Used to filter out. +const FileSearchFlags RS_FILE_HINTS_NETWORK_WIDE ( 0x00000080 );// anonymously shared over network +const FileSearchFlags RS_FILE_HINTS_BROWSABLE ( 0x00000100 );// browsable by friends +const FileSearchFlags RS_FILE_HINTS_PERMISSION_MASK ( 0x00000180 );// OR of the last two flags. Used to filter out. // Flags used when requesting a transfer // const TransferRequestFlags RS_FILE_REQ_ANONYMOUS_ROUTING ( 0x00000040 ); // Use to ask turtle router to download the file. +const TransferRequestFlags RS_FILE_REQ_ENCRYPTED ( 0x00000080 ); // Asks for end-to-end encryption of file at the level of ftServer const TransferRequestFlags RS_FILE_REQ_ASSUME_AVAILABILITY ( 0x00000200 ); // Assume full source availability. Used for cache files. -const TransferRequestFlags RS_FILE_REQ_CACHE_deprecated ( 0x00000400 ); // Assume full source availability. Used for cache files. +const TransferRequestFlags RS_FILE_REQ_CACHE_deprecated ( 0x00000400 ); // Old stuff used for cache files. Not used anymore. const TransferRequestFlags RS_FILE_REQ_EXTRA ( 0x00000800 ); -const TransferRequestFlags RS_FILE_REQ_MEDIA ( 0x00001000 ); -const TransferRequestFlags RS_FILE_REQ_BACKGROUND ( 0x00002000 ); // To download slowly. +const TransferRequestFlags RS_FILE_REQ_MEDIA ( 0x00001000 ); +const TransferRequestFlags RS_FILE_REQ_BACKGROUND ( 0x00002000 ); // To download slowly. const TransferRequestFlags RS_FILE_REQ_NO_SEARCH ( 0x02000000 ); // disable searching for potential direct sources. // const uint32_t RS_FILE_HINTS_SHARE_FLAGS_MASK = RS_FILE_HINTS_NETWORK_WIDE_OTHERS | RS_FILE_HINTS_BROWSABLE_OTHERS From 0570427c1d05858512ff1146bd84022fedf6fc61 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Tue, 25 Oct 2016 14:09:39 +0200 Subject: [PATCH 06/52] added google test for chacha20 code --- libretroshare/src/crypto/chacha20.cpp | 122 +++++++++++------- libretroshare/src/crypto/chacha20.h | 8 +- .../libretroshare/crypto/chacha20_test.cc | 12 ++ tests/unittests/unittests.pro | 4 + 4 files changed, 94 insertions(+), 52 deletions(-) create mode 100644 tests/unittests/libretroshare/crypto/chacha20_test.cc diff --git a/libretroshare/src/crypto/chacha20.cpp b/libretroshare/src/crypto/chacha20.cpp index 24e810283..7e7c3a255 100644 --- a/libretroshare/src/crypto/chacha20.cpp +++ b/libretroshare/src/crypto/chacha20.cpp @@ -22,7 +22,6 @@ * Please report all bugs and problems to "retroshare.project@gmail.com". * */ -#include #include #include #include @@ -35,8 +34,6 @@ #include "crypto/chacha20.h" -#pragma once - #define rotl(x,n) { x = (x << n) | (x >> (-n & 31)) ;} namespace librs { @@ -164,14 +161,16 @@ struct uint256_32 } *this = r; - assert(!(b[0] & 0xffffffff00000000)) ; - assert(!(b[1] & 0xffffffff00000000)) ; - assert(!(b[2] & 0xffffffff00000000)) ; - assert(!(b[3] & 0xffffffff00000000)) ; - assert(!(b[4] & 0xffffffff00000000)) ; - assert(!(b[5] & 0xffffffff00000000)) ; - assert(!(b[6] & 0xffffffff00000000)) ; - assert(!(b[7] & 0xffffffff00000000)) ; +#ifdef DEBUG_CHACHA20 + if(!(!(b[0] & 0xffffffff00000000))) throw() ; + if(!(!(b[1] & 0xffffffff00000000))) throw() ; + if(!(!(b[2] & 0xffffffff00000000))) throw() ; + if(!(!(b[3] & 0xffffffff00000000))) throw() ; + if(!(!(b[4] & 0xffffffff00000000))) throw() ; + if(!(!(b[5] & 0xffffffff00000000))) throw() ; + if(!(!(b[6] & 0xffffffff00000000))) throw() ; + if(!(!(b[7] & 0xffffffff00000000))) throw() ; +#endif } static void print(const uint256_32& s) @@ -302,6 +301,7 @@ static void apply_20_rounds(chacha20_state& s) } } +#ifdef DEBUG_CHACHA20 static void print(const chacha20_state& s) { fprintf(stdout,"%08x %08x %08x %08x\n",s.c[0 ],s.c[1 ],s.c[2 ],s.c[3 ]) ; @@ -309,6 +309,7 @@ static void print(const chacha20_state& s) fprintf(stdout,"%08x %08x %08x %08x\n",s.c[8 ],s.c[9 ],s.c[10],s.c[11]) ; fprintf(stdout,"%08x %08x %08x %08x\n",s.c[12],s.c[13],s.c[14],s.c[15]) ; } +#endif static void add(chacha20_state& s,const chacha20_state& t) { for(uint32_t i=0;i<16;++i) s.c[i] += t.c[i] ; } @@ -374,14 +375,18 @@ void chacha20_encrypt(uint8_t key[32], uint32_t block_counter, uint8_t nonce[12] chacha20_state s(key,block_counter+i,nonce) ; chacha20_state t(s) ; +#ifdef DEBUG_CHACHA20 fprintf(stdout,"Block %d:\n",i) ; print(s) ; +#endif apply_20_rounds(s) ; add(s,t) ; +#ifdef DEBUG_CHACHA20 fprintf(stdout,"Cipher %d:\n",i) ; print(s) ; +#endif for(uint32_t k=0;k<64;++k) if(k+64*i < size) @@ -528,13 +533,11 @@ bool AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uin } } -void perform_tests() +bool perform_tests() { - std::cerr << "Testing Chacha20" << std::endl; - // RFC7539 - 2.1.1 - std::cerr << " quarter round..." ; + std::cerr << " quarter round " ; uint32_t a = 0x11111111 ; uint32_t b = 0x01020304 ; @@ -543,16 +546,16 @@ void perform_tests() quarter_round(a,b,c,d) ; - assert(a == 0xea2a92f4) ; - assert(b == 0xcb1cf8ce) ; - assert(c == 0x4581472e) ; - assert(d == 0x5881c4bb) ; + if(!(a == 0xea2a92f4)) return false ; + if(!(b == 0xcb1cf8ce)) return false ; + if(!(c == 0x4581472e)) return false ; + if(!(d == 0x5881c4bb)) return false ; - std::cerr << " - OK" << std::endl; + std::cerr << " OK" << std::endl; // RFC7539 - 2.3.2 - std::cerr << " RFC7539 - 2.3.2..." ; + std::cerr << " RFC7539 - 2.3.2 " ; uint8_t key[32] = { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b, \ 0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17, \ @@ -562,24 +565,39 @@ void perform_tests() chacha20_state s(key,1,nounce) ; chacha20_state t(s) ; +#ifdef DEBUG_CHACHA20 print(s) ; - - fprintf(stdout,"\n") ; +#endif apply_20_rounds(s) ; +#ifdef DEBUG_CHACHA20 print(s) ; +#endif add(t,s) ; +#ifdef DEBUG_CHACHA20 fprintf(stdout,"\n") ; print(t) ; +#endif - std::cerr << " - OK" << std::endl; + uint32_t check_vals[16] = { + 0xe4e7f110, 0x15593bd1, 0x1fdd0f50, 0xc47120a3, + 0xc7f4d1c7, 0x0368c033, 0x9aaa2204, 0x4e6cd4c3, + 0x466482d2, 0x09aa9f07, 0x05d7c214, 0xa2028bd9, + 0xd19c12b5, 0xb94e16de, 0xe883d0cb, 0x4e3c50a2 + }; + + for(uint32_t i=0;i<16;++i) + if(t.c[i] != check_vals[i]) + return false ; + + std::cerr << " OK" << std::endl; // RFC7539 - 2.4.2 - std::cerr << " RFC7539 - 2.4.2..." ; + std::cerr << " RFC7539 - 2.4.2 " ; uint8_t nounce2[12] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x4a,0x00,0x00,0x00,0x00 } ; @@ -596,7 +614,7 @@ void perform_tests() chacha20_encrypt(key,1,nounce2,plaintext,7*16+2) ; -#ifdef PRINT_RESULTS +#ifdef DEBUG_CHACHA20 fprintf(stdout,"CipherText: \n") ; for(uint32_t k=0;k<7*16+2;++k) @@ -621,9 +639,10 @@ void perform_tests() }; for(uint32_t i=0;i<7*16+2;++i) - assert(check_cipher_text[i] == plaintext[i] ); + if(!(check_cipher_text[i] == plaintext[i] )) + return false; - std::cerr << " - OK" << std::endl; + std::cerr << " OK" << std::endl; // sums/diffs of numbers @@ -631,7 +650,7 @@ void perform_tests() { uint256_32 a = uint256_32::random() ; uint256_32 b = uint256_32::random() ; -#ifdef PRINT_RESULTS +#ifdef DEBUG_CHACHA20 fprintf(stdout,"Adding ") ; uint256_32::print(a) ; fprintf(stdout,"\n to ") ; @@ -639,25 +658,26 @@ void perform_tests() #endif uint256_32 c(a) ; - assert(c == a) ; + if(!(c == a) ) + return false; c += b ; -#ifdef PRINT_RESULTS +#ifdef DEBUG_CHACHA20 fprintf(stdout,"\n found ") ; uint256_32::print(c) ; #endif c -= b ; -#ifdef PRINT_RESULTS +#ifdef DEBUG_CHACHA20 fprintf(stdout,"\n subst ") ; uint256_32::print(c) ; fprintf(stdout,"\n") ; #endif - assert(a == a) ; - assert(c == a) ; + if(!(a == a)) return false ; + if(!(c == a)) return false ; } std::cerr << " Sums / diffs of 256bits numbers OK" << std::endl; @@ -687,7 +707,7 @@ void perform_tests() atcmbtcmatdpbtd -= atd ; atcmbtcmatdpbtd += btd ; - assert(atcmbtcmatdpbtd == ambtcmd); + if(!(atcmbtcmatdpbtd == ambtcmd)) return false ; } std::cerr << " (a-b)*(c-d) == ac-bc-ad+bd on random OK" << std::endl; @@ -704,7 +724,7 @@ void perform_tests() x.b[0] += r ; - assert(x == y) ; + if(!(x == y) ) return false ; } std::cerr << " left/right shifting OK" << std::endl; @@ -726,7 +746,7 @@ void perform_tests() } quotient(n1,p1,q1,r1) ; -#ifdef PRINT_RESULTS +#ifdef DEBUG_CHACHA20 fprintf(stdout,"result: q=") ; chacha20::uint256_32::print(q1) ; fprintf(stdout," r=") ; chacha20::uint256_32::print(r1) ; fprintf(stdout,"\n") ; #endif @@ -734,7 +754,7 @@ void perform_tests() q1 *= p1 ; q1 += r1 ; - assert(q1 == n1) ; + if(!(q1 == n1)) return false ; } std::cerr << " Quotient/modulo on random numbers OK" << std::endl; @@ -749,7 +769,7 @@ void perform_tests() uint8_t test_tag[16] = { 0xa8,0x06,0x1d,0xc1,0x30,0x51,0x36,0xc6,0xc2,0x2b,0x8b,0xaf,0x0c,0x01,0x27,0xa9 }; - assert(constant_time_memory_compare(tag,test_tag,16)) ; + if(!(constant_time_memory_compare(tag,test_tag,16))) return false ; } std::cerr << " RFC7539 poly1305 test vector #001 OK" << std::endl; @@ -767,7 +787,7 @@ void perform_tests() uint8_t test_tag[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; - assert(constant_time_memory_compare(tag,test_tag,16)) ; + if(!(constant_time_memory_compare(tag,test_tag,16)) ) return false ; } std::cerr << " RFC7539 poly1305 test vector #002 OK" << std::endl; @@ -786,7 +806,7 @@ void perform_tests() uint8_t test_tag[16] = { 0x36,0xe5,0xf6,0xb5,0xc5,0xe0,0x60,0x70,0xf0,0xef,0xca,0x96,0x22,0x7a,0x86,0x3e }; - assert(constant_time_memory_compare(tag,test_tag,16)) ; + if(!(constant_time_memory_compare(tag,test_tag,16)) ) return false ; } std::cerr << " RFC7539 poly1305 test vector #003 OK" << std::endl; @@ -805,7 +825,7 @@ void perform_tests() uint8_t test_tag[16] = { 0xf3,0x47,0x7e,0x7c,0xd9,0x54,0x17,0xaf,0x89,0xa6,0xb8,0x79,0x4c,0x31,0x0c,0xf0 } ; - assert(constant_time_memory_compare(tag,test_tag,16)) ; + if(!(constant_time_memory_compare(tag,test_tag,16)) ) return false ; } std::cerr << " RFC7539 poly1305 test vector #004 OK" << std::endl; @@ -822,7 +842,7 @@ void perform_tests() uint8_t test_tag[16] = { 0x45,0x41,0x66,0x9a,0x7e,0xaa,0xee,0x61,0xe7,0x08,0xdc,0x7c,0xbc,0xc5,0xeb,0x62 } ; - assert(constant_time_memory_compare(tag,test_tag,16)) ; + if(!(constant_time_memory_compare(tag,test_tag,16)) ) return false ; } std::cerr << " RFC7539 poly1305 test vector #005 OK" << std::endl; @@ -840,7 +860,7 @@ void perform_tests() uint8_t test_tag[16] = { 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } ; - assert(constant_time_memory_compare(tag,test_tag,16)) ; + if(!(constant_time_memory_compare(tag,test_tag,16)) ) return false ; } std::cerr << " RFC7539 poly1305 test vector #006 OK" << std::endl; @@ -858,7 +878,7 @@ void perform_tests() uint8_t test_tag[16] = { 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } ; - assert(constant_time_memory_compare(tag,test_tag,16)) ; + if(!(constant_time_memory_compare(tag,test_tag,16)) ) return false ; } std::cerr << " RFC7539 poly1305 test vector #007 OK" << std::endl; @@ -877,7 +897,7 @@ void perform_tests() uint8_t test_tag[16] = { 0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } ; - assert(constant_time_memory_compare(tag,test_tag,16)) ; + if(!(constant_time_memory_compare(tag,test_tag,16)) ) return false ; } std::cerr << " RFC7539 poly1305 test vector #008 OK" << std::endl; @@ -896,7 +916,7 @@ void perform_tests() uint8_t test_tag[16] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } ; - assert(constant_time_memory_compare(tag,test_tag,16)) ; + if(!(constant_time_memory_compare(tag,test_tag,16)) ) return false ; } std::cerr << " RFC7539 poly1305 test vector #009 OK" << std::endl; @@ -913,7 +933,7 @@ void perform_tests() uint8_t test_tag[16] = { 0xfa,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff } ; - assert(constant_time_memory_compare(tag,test_tag,16)) ; + if(!(constant_time_memory_compare(tag,test_tag,16)) ) return false ; } std::cerr << " RFC7539 poly1305 test vector #010 OK" << std::endl; @@ -934,7 +954,7 @@ void perform_tests() uint8_t test_tag[16] = { 0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x55,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } ; - assert(constant_time_memory_compare(tag,test_tag,16)) ; + if(!(constant_time_memory_compare(tag,test_tag,16)) ) return false ; } std::cerr << " RFC7539 poly1305 test vector #011 OK" << std::endl; @@ -954,8 +974,10 @@ void perform_tests() uint8_t test_tag[16] = { 0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } ; - assert(constant_time_memory_compare(tag,test_tag,16)) ; + if(!constant_time_memory_compare(tag,test_tag,16)) return false ; } + + return true; } } diff --git a/libretroshare/src/crypto/chacha20.h b/libretroshare/src/crypto/chacha20.h index 361e2743f..d2668aea3 100644 --- a/libretroshare/src/crypto/chacha20.h +++ b/libretroshare/src/crypto/chacha20.h @@ -23,6 +23,8 @@ * */ +#include + namespace librs { namespace crypto @@ -77,15 +79,17 @@ namespace librs * \param size common size of m1 and m2 * \return * false if the two chunks are different - * true if the two chunks are different + * true if the two chunks are identical */ bool constant_time_memory_compare(const uint8_t *m1,const uint8_t *m2,uint32_t size) ; /*! * \brief perform_tests * Tests all methods in this class, using the tests supplied in RFC7539 + * \return + * true is all tests pass */ - void perform_tests() ; + bool perform_tests() ; } } diff --git a/tests/unittests/libretroshare/crypto/chacha20_test.cc b/tests/unittests/libretroshare/crypto/chacha20_test.cc new file mode 100644 index 000000000..8cd203cb3 --- /dev/null +++ b/tests/unittests/libretroshare/crypto/chacha20_test.cc @@ -0,0 +1,12 @@ +#include + +// from libretroshare + +#include "crypto/chacha20.h" + +TEST(libretroshare_crypto, ChaCha20) +{ + std::cerr << "Testing Chacha20" << std::endl; + + EXPECT_TRUE(librs::crypto::perform_tests()) ; +} diff --git a/tests/unittests/unittests.pro b/tests/unittests/unittests.pro index d0485ca92..c72520344 100644 --- a/tests/unittests/unittests.pro +++ b/tests/unittests/unittests.pro @@ -271,6 +271,10 @@ INCLUDEPATH += ../librssimulator/ SOURCES += unittests.cc \ +################################## Crypto ################################## + +SOURCES += libretroshare/crypto/chacha20_test.cc + ################################ Serialiser ################################ HEADERS += libretroshare/serialiser/support.h \ libretroshare/serialiser/rstlvutil.h \ From 177752e6af3a6223660e48db85b4e44f9c54ae3c Mon Sep 17 00:00:00 2001 From: mr-alice Date: Tue, 25 Oct 2016 23:16:36 +0200 Subject: [PATCH 07/52] fixed a few bugs in AEAD construction based on test results --- libretroshare/src/crypto/chacha20.cpp | 129 ++++++++++++++++++-------- libretroshare/src/ft/ftserver.cc | 1 + 2 files changed, 89 insertions(+), 41 deletions(-) diff --git a/libretroshare/src/crypto/chacha20.cpp b/libretroshare/src/crypto/chacha20.cpp index 7e7c3a255..6c48957c1 100644 --- a/libretroshare/src/crypto/chacha20.cpp +++ b/libretroshare/src/crypto/chacha20.cpp @@ -286,8 +286,12 @@ static void quarter_round(uint32_t& a,uint32_t& b,uint32_t& c,uint32_t& d) c += d ; b ^= c; rotl(b,7) ; //b <<<=7 ; } +static void add(chacha20_state& s,const chacha20_state& t) { for(uint32_t i=0;i<16;++i) s.c[i] += t.c[i] ; } + static void apply_20_rounds(chacha20_state& s) { + chacha20_state t(s) ; + for(uint32_t i=0;i<10;++i) { quarter_round(s.c[ 0],s.c[ 4],s.c[ 8],s.c[12]) ; @@ -299,9 +303,10 @@ static void apply_20_rounds(chacha20_state& s) quarter_round(s.c[ 2],s.c[ 7],s.c[ 8],s.c[13]) ; quarter_round(s.c[ 3],s.c[ 4],s.c[ 9],s.c[14]) ; } + + add(s,t) ; } -#ifdef DEBUG_CHACHA20 static void print(const chacha20_state& s) { fprintf(stdout,"%08x %08x %08x %08x\n",s.c[0 ],s.c[1 ],s.c[2 ],s.c[3 ]) ; @@ -309,9 +314,6 @@ static void print(const chacha20_state& s) fprintf(stdout,"%08x %08x %08x %08x\n",s.c[8 ],s.c[9 ],s.c[10],s.c[11]) ; fprintf(stdout,"%08x %08x %08x %08x\n",s.c[12],s.c[13],s.c[14],s.c[15]) ; } -#endif - -static void add(chacha20_state& s,const chacha20_state& t) { for(uint32_t i=0;i<16;++i) s.c[i] += t.c[i] ; } // static uint8_t read16bits(char s) // { @@ -373,15 +375,12 @@ void chacha20_encrypt(uint8_t key[32], uint32_t block_counter, uint8_t nonce[12] for(uint32_t i=0;i> 8*i) & 0xff ; } @@ -490,16 +489,17 @@ bool AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uin uint8_t session_key[32]; poly1305_key_gen(key,nonce,session_key); - uint8_t lengths_vector[16] ; - for(uint32_t i=0;i<8;++i) + uint8_t lengths_vector[16] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } ; + + for(uint32_t i=0;i<4;++i) { - lengths_vector[0+i] = ( aad_size >> i) & 0xff ; - lengths_vector[8+i] = (data_size >> i) & 0xff ; + lengths_vector[0+i] = ( aad_size >> (8*i)) & 0xff ; + lengths_vector[8+i] = (data_size >> (8*i)) & 0xff ; } if(encrypt) { - chacha20_encrypt(session_key,1,nonce,data,data_size); + chacha20_encrypt(key,1,nonce,data,data_size); poly1305_state pls ; @@ -527,7 +527,7 @@ bool AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uin // decrypt - chacha20_encrypt(session_key,1,nonce,data,data_size); + chacha20_encrypt(key,1,nonce,data,data_size); return constant_time_memory_compare(tag,computed_tag,16) ; } @@ -563,7 +563,6 @@ bool perform_tests() uint8_t nounce[12] = { 0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x4a,0x00,0x00,0x00,0x00 } ; chacha20_state s(key,1,nounce) ; - chacha20_state t(s) ; #ifdef DEBUG_CHACHA20 print(s) ; @@ -571,15 +570,10 @@ bool perform_tests() apply_20_rounds(s) ; -#ifdef DEBUG_CHACHA20 - print(s) ; -#endif - add(t,s) ; - #ifdef DEBUG_CHACHA20 fprintf(stdout,"\n") ; - print(t) ; + print(s) ; #endif uint32_t check_vals[16] = { @@ -590,7 +584,7 @@ bool perform_tests() }; for(uint32_t i=0;i<16;++i) - if(t.c[i] != check_vals[i]) + if(s.c[i] != check_vals[i]) return false ; std::cerr << " OK" << std::endl; @@ -771,12 +765,10 @@ bool perform_tests() if(!(constant_time_memory_compare(tag,test_tag,16))) return false ; } - - std::cerr << " RFC7539 poly1305 test vector #001 OK" << std::endl; + std::cerr << " RFC7539 - 2.5 OK" << std::endl; // RFC7539 - Poly1305 test vector #1 // - { uint8_t key[32] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } ; uint8_t tag[16] ; @@ -789,12 +781,10 @@ bool perform_tests() if(!(constant_time_memory_compare(tag,test_tag,16)) ) return false ; } - - std::cerr << " RFC7539 poly1305 test vector #002 OK" << std::endl; + std::cerr << " RFC7539 poly1305 test vector #001 OK" << std::endl; // RFC7539 - Poly1305 test vector #2 // - { uint8_t key[32] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x36,0xe5,0xf6,0xb5,0xc5,0xe0,0x60,0x70,0xf0,0xef,0xca,0x96,0x22,0x7a,0x86,0x3e } ; @@ -808,12 +798,10 @@ bool perform_tests() if(!(constant_time_memory_compare(tag,test_tag,16)) ) return false ; } - - std::cerr << " RFC7539 poly1305 test vector #003 OK" << std::endl; + std::cerr << " RFC7539 poly1305 test vector #002 OK" << std::endl; // RFC7539 - Poly1305 test vector #3 // - { uint8_t key[32] = { 0x36,0xe5,0xf6,0xb5,0xc5,0xe0,0x60,0x70,0xf0,0xef,0xca,0x96,0x22,0x7a,0x86,0x3e, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } ; @@ -827,8 +815,8 @@ bool perform_tests() if(!(constant_time_memory_compare(tag,test_tag,16)) ) return false ; } + std::cerr << " RFC7539 poly1305 test vector #003 OK" << std::endl; - std::cerr << " RFC7539 poly1305 test vector #004 OK" << std::endl; // RFC7539 - Poly1305 test vector #4 // { @@ -844,8 +832,7 @@ bool perform_tests() if(!(constant_time_memory_compare(tag,test_tag,16)) ) return false ; } - - std::cerr << " RFC7539 poly1305 test vector #005 OK" << std::endl; + std::cerr << " RFC7539 poly1305 test vector #004 OK" << std::endl; // RFC7539 - Poly1305 test vector #5 // @@ -862,8 +849,7 @@ bool perform_tests() if(!(constant_time_memory_compare(tag,test_tag,16)) ) return false ; } - - std::cerr << " RFC7539 poly1305 test vector #006 OK" << std::endl; + std::cerr << " RFC7539 poly1305 test vector #005 OK" << std::endl; // RFC7539 - Poly1305 test vector #6 // @@ -880,7 +866,7 @@ bool perform_tests() if(!(constant_time_memory_compare(tag,test_tag,16)) ) return false ; } - std::cerr << " RFC7539 poly1305 test vector #007 OK" << std::endl; + std::cerr << " RFC7539 poly1305 test vector #006 OK" << std::endl; // RFC7539 - Poly1305 test vector #7 // @@ -899,7 +885,7 @@ bool perform_tests() if(!(constant_time_memory_compare(tag,test_tag,16)) ) return false ; } - std::cerr << " RFC7539 poly1305 test vector #008 OK" << std::endl; + std::cerr << " RFC7539 poly1305 test vector #007 OK" << std::endl; // RFC7539 - Poly1305 test vector #8 // @@ -918,7 +904,7 @@ bool perform_tests() if(!(constant_time_memory_compare(tag,test_tag,16)) ) return false ; } - std::cerr << " RFC7539 poly1305 test vector #009 OK" << std::endl; + std::cerr << " RFC7539 poly1305 test vector #008 OK" << std::endl; // RFC7539 - Poly1305 test vector #9 // @@ -935,7 +921,7 @@ bool perform_tests() if(!(constant_time_memory_compare(tag,test_tag,16)) ) return false ; } - std::cerr << " RFC7539 poly1305 test vector #010 OK" << std::endl; + std::cerr << " RFC7539 poly1305 test vector #009 OK" << std::endl; // RFC7539 - Poly1305 test vector #10 // @@ -956,7 +942,7 @@ bool perform_tests() if(!(constant_time_memory_compare(tag,test_tag,16)) ) return false ; } - std::cerr << " RFC7539 poly1305 test vector #011 OK" << std::endl; + std::cerr << " RFC7539 poly1305 test vector #010 OK" << std::endl; // RFC7539 - Poly1305 test vector #11 // @@ -976,6 +962,67 @@ bool perform_tests() if(!constant_time_memory_compare(tag,test_tag,16)) return false ; } + std::cerr << " RFC7539 poly1305 test vector #011 OK" << std::endl; + + // RFC7539 - 2.6.2 + // + { + uint8_t key[32] = { 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, + 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f }; + + uint8_t session_key[32] ; + uint8_t test_session_key[32] = { 0x8a,0xd5,0xa0,0x8b,0x90,0x5f,0x81,0xcc,0x81,0x50,0x40,0x27,0x4a,0xb2,0x94,0x71, + 0xa8,0x33,0xb6,0x37,0xe3,0xfd,0x0d,0xa5,0x08,0xdb,0xb8,0xe2,0xfd,0xd1,0xa6,0x46 }; + + uint8_t nonce[12] = { 0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07 }; + + poly1305_key_gen(key,nonce,session_key) ; + + if(!constant_time_memory_compare(session_key,test_session_key,32)) return false ; + } + std::cerr << " RFC7539 - 2.6.2 OK" << std::endl; + + // RFC7539 - 2.8.2 + // + { + uint8_t msg[7*16+2] = { + 0x4c,0x61,0x64,0x69,0x65,0x73,0x20,0x61,0x6e,0x64,0x20,0x47,0x65,0x6e,0x74,0x6c, + 0x65,0x6d,0x65,0x6e,0x20,0x6f,0x66,0x20,0x74,0x68,0x65,0x20,0x63,0x6c,0x61,0x73, + 0x73,0x20,0x6f,0x66,0x20,0x27,0x39,0x39,0x3a,0x20,0x49,0x66,0x20,0x49,0x20,0x63, + 0x6f,0x75,0x6c,0x64,0x20,0x6f,0x66,0x66,0x65,0x72,0x20,0x79,0x6f,0x75,0x20,0x6f, + 0x6e,0x6c,0x79,0x20,0x6f,0x6e,0x65,0x20,0x74,0x69,0x70,0x20,0x66,0x6f,0x72,0x20, + 0x74,0x68,0x65,0x20,0x66,0x75,0x74,0x75,0x72,0x65,0x2c,0x20,0x73,0x75,0x6e,0x73, + 0x63,0x72,0x65,0x65,0x6e,0x20,0x77,0x6f,0x75,0x6c,0x64,0x20,0x62,0x65,0x20,0x69, + 0x74,0x2e } ; + + uint8_t test_msg[7*16+2] = { + 0xd3,0x1a,0x8d,0x34,0x64,0x8e,0x60,0xdb,0x7b,0x86,0xaf,0xbc,0x53,0xef,0x7e,0xc2, + 0xa4,0xad,0xed,0x51,0x29,0x6e,0x08,0xfe,0xa9,0xe2,0xb5,0xa7,0x36,0xee,0x62,0xd6, + 0x3d,0xbe,0xa4,0x5e,0x8c,0xa9,0x67,0x12,0x82,0xfa,0xfb,0x69,0xda,0x92,0x72,0x8b, + 0x1a,0x71,0xde,0x0a,0x9e,0x06,0x0b,0x29,0x05,0xd6,0xa5,0xb6,0x7e,0xcd,0x3b,0x36, + 0x92,0xdd,0xbd,0x7f,0x2d,0x77,0x8b,0x8c,0x98,0x03,0xae,0xe3,0x28,0x09,0x1b,0x58, + 0xfa,0xb3,0x24,0xe4,0xfa,0xd6,0x75,0x94,0x55,0x85,0x80,0x8b,0x48,0x31,0xd7,0xbc, + 0x3f,0xf4,0xde,0xf0,0x8e,0x4b,0x7a,0x9d,0xe5,0x76,0xd2,0x65,0x86,0xce,0xc6,0x4b, + 0x61,0x16 }; + + uint8_t aad[12] = { 0x50,0x51,0x52,0x53,0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7 }; + uint8_t nonce[12] = { 0x07,0x00,0x00,0x00,0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47 }; + + uint8_t key[32] = { 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, + 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f }; + uint8_t tag[16] ; + uint8_t test_tag[16] = { 0x1a,0xe1,0x0b,0x59,0x4f,0x09,0xe2,0x6a,0x7e,0x90,0x2e,0xcb,0xd0,0x60,0x06,0x91 }; + + librs::crypto::AEAD_chacha20_poly1305(key,nonce,msg,7*16+2,aad,12,tag,true) ; + + if(!constant_time_memory_compare(msg,test_msg,7*16+2)) return false ; + if(!constant_time_memory_compare(tag,test_tag,16)) return false ; + + bool res = librs::crypto::AEAD_chacha20_poly1305(key,nonce,msg,7*16+2,aad,12,tag,false) ; + + if(!res) return false ; + } + std::cerr << " RFC7539 - 2.8.2305 OK" << std::endl; return true; } diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index e5476f725..3c88c6692 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -462,6 +462,7 @@ bool ftServer::handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_i FileInfo info ; bool res = FileDetails(hash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY, info); +#warning need code here => turn H(H) into real hash if( (!res) && FileDetails(hash,RS_FILE_HINTS_DOWNLOAD,info)) { // This file is currently being downloaded. Let's look if we already have a chunk or not. If not, no need to From 42f6f26820d5e3e395910b3c179d612717d05a23 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Wed, 26 Oct 2016 14:36:35 +0200 Subject: [PATCH 08/52] fixed bug in AEAD --- libretroshare/src/crypto/chacha20.cpp | 122 +++++++++++++++++++++++--- 1 file changed, 110 insertions(+), 12 deletions(-) diff --git a/libretroshare/src/crypto/chacha20.cpp b/libretroshare/src/crypto/chacha20.cpp index 6c48957c1..756bbdc32 100644 --- a/libretroshare/src/crypto/chacha20.cpp +++ b/libretroshare/src/crypto/chacha20.cpp @@ -33,6 +33,7 @@ #include #include "crypto/chacha20.h" +#include "util/rsprint.h" #define rotl(x,n) { x = (x << n) | (x >> (-n & 31)) ;} @@ -425,8 +426,12 @@ static void poly1305_init(poly1305_state& s,uint8_t key[32]) // Warning: each call will automatically *pad* the data to a multiple of 16 bytes. // -static void poly1305_add(poly1305_state& s,uint8_t *message,uint32_t size) +static void poly1305_add(poly1305_state& s,uint8_t *message,uint32_t size,bool pad_to_16_bytes=false) { +#ifdef DEBUG_CHACHA20 + std::cerr << "Poly1305: digesting " << RsUtil::BinToHex(message,size) << std::endl; +#endif + for(uint32_t i=0;i<(size+15)/16;++i) { uint256_32 block ; @@ -435,7 +440,10 @@ static void poly1305_add(poly1305_state& s,uint8_t *message,uint32_t size) for(j=0;j<16 && i*16+j < size;++j) block.b[j/4] += ((uint64_t)message[i*16+j]) << (8*(j & 0x3)) ; - block.b[j/4] += 0x01 << (8*(j& 0x3)); + if(pad_to_16_bytes) + block.b[4] += 0x01 ; + else + block.b[j/4] += 0x01 << (8*(j& 0x3)); s.a += block ; s.a *= s.r ; @@ -461,7 +469,7 @@ void poly1305_tag(uint8_t key[32],uint8_t *message,uint32_t size,uint8_t tag[16] poly1305_state s; poly1305_init (s,key); - poly1305_add (s,message,size); + poly1305_add(s,message,size) ; poly1305_finish(s,tag); } @@ -505,9 +513,9 @@ bool AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uin poly1305_init(pls,session_key); - poly1305_add(pls,aad,aad_size); // add and pad the aad - poly1305_add(pls,data,data_size); // add and pad the cipher text - poly1305_add(pls,lengths_vector,16); // add the lengths + poly1305_add(pls,aad,aad_size,true); // add and pad the aad + poly1305_add(pls,data,data_size,true); // add and pad the cipher text + poly1305_add(pls,lengths_vector,16,true); // add the lengths poly1305_finish(pls,tag); return true ; @@ -519,9 +527,9 @@ bool AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uin poly1305_init(pls,session_key); - poly1305_add(pls,aad,aad_size); // add and pad the aad - poly1305_add(pls,data,data_size); // add and pad the cipher text - poly1305_add(pls,lengths_vector,16); // add the lengths + poly1305_add(pls,aad,aad_size,true); // add and pad the aad + poly1305_add(pls,data,data_size,true); // add and pad the cipher text + poly1305_add(pls,lengths_vector,16,true); // add the lengths poly1305_finish(pls,computed_tag); @@ -982,6 +990,59 @@ bool perform_tests() } std::cerr << " RFC7539 - 2.6.2 OK" << std::endl; + // RFC7539 - Poly1305 key generation. Test vector #1 + // + { + uint8_t key[32] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; + + uint8_t nonce[12] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }; + uint8_t session_key[32] ; + uint8_t test_session_key[32] = { 0x76,0xb8,0xe0,0xad,0xa0,0xf1,0x3d,0x90,0x40,0x5d,0x6a,0xe5,0x53,0x86,0xbd,0x28, + 0xbd,0xd2,0x19,0xb8,0xa0,0x8d,0xed,0x1a,0xa8,0x36,0xef,0xcc,0x8b,0x77,0x0d,0xc7 }; + + poly1305_key_gen(key,nonce,session_key) ; + + if(!constant_time_memory_compare(session_key,test_session_key,32)) return false ; + } + std::cerr << " RFC7539 poly1305 key gen. TVec #1 OK" << std::endl; + + // RFC7539 - Poly1305 key generation. Test vector #2 + // + { + uint8_t key[32] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01 }; + + uint8_t nonce[12] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02 }; + uint8_t session_key[32] ; + uint8_t test_session_key[32] = { 0xec,0xfa,0x25,0x4f,0x84,0x5f,0x64,0x74,0x73,0xd3,0xcb,0x14,0x0d,0xa9,0xe8,0x76, + 0x06,0xcb,0x33,0x06,0x6c,0x44,0x7b,0x87,0xbc,0x26,0x66,0xdd,0xe3,0xfb,0xb7,0x39 }; + + + + poly1305_key_gen(key,nonce,session_key) ; + + if(!constant_time_memory_compare(session_key,test_session_key,32)) return false ; + } + std::cerr << " RFC7539 poly1305 key gen. TVec #2 OK" << std::endl; + + // RFC7539 - Poly1305 key generation. Test vector #3 + // + { + uint8_t key[32] = { 0x1c,0x92,0x40,0xa5,0xeb,0x55,0xd3,0x8a,0xf3,0x33,0x88,0x86,0x04,0xf6,0xb5,0xf0, + 0x47,0x39,0x17,0xc1,0x40,0x2b,0x80,0x09,0x9d,0xca,0x5c,0xbc,0x20,0x70,0x75,0xc0 }; + + uint8_t nonce[12] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02 }; + uint8_t session_key[32] ; + uint8_t test_session_key[32] = { 0x96,0x5e,0x3b,0xc6,0xf9,0xec,0x7e,0xd9,0x56,0x08,0x08,0xf4,0xd2,0x29,0xf9,0x4b, + 0x13,0x7f,0xf2,0x75,0xca,0x9b,0x3f,0xcb,0xdd,0x59,0xde,0xaa,0xd2,0x33,0x10,0xae }; + + poly1305_key_gen(key,nonce,session_key) ; + + if(!constant_time_memory_compare(session_key,test_session_key,32)) return false ; + } + std::cerr << " RFC7539 poly1305 key gen. TVec #3 OK" << std::endl; + // RFC7539 - 2.8.2 // { @@ -1013,16 +1074,53 @@ bool perform_tests() uint8_t tag[16] ; uint8_t test_tag[16] = { 0x1a,0xe1,0x0b,0x59,0x4f,0x09,0xe2,0x6a,0x7e,0x90,0x2e,0xcb,0xd0,0x60,0x06,0x91 }; - librs::crypto::AEAD_chacha20_poly1305(key,nonce,msg,7*16+2,aad,12,tag,true) ; + AEAD_chacha20_poly1305(key,nonce,msg,7*16+2,aad,12,tag,true) ; if(!constant_time_memory_compare(msg,test_msg,7*16+2)) return false ; if(!constant_time_memory_compare(tag,test_tag,16)) return false ; - bool res = librs::crypto::AEAD_chacha20_poly1305(key,nonce,msg,7*16+2,aad,12,tag,false) ; + bool res = AEAD_chacha20_poly1305(key,nonce,msg,7*16+2,aad,12,tag,false) ; if(!res) return false ; } - std::cerr << " RFC7539 - 2.8.2305 OK" << std::endl; + std::cerr << " RFC7539 - 2.8.2 OK" << std::endl; + + + // RFC7539 - AEAD checking and decryption + // + { + uint8_t key[32] = { 0x1c,0x92,0x40,0xa5,0xeb,0x55,0xd3,0x8a,0xf3,0x33,0x88,0x86,0x04,0xf6,0xb5,0xf0, + 0x47,0x39,0x17,0xc1,0x40,0x2b,0x80,0x09,0x9d,0xca,0x5c,0xbc,0x20,0x70,0x75,0xc0 }; + + uint8_t nonce[12] = { 0x00,0x00,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08 }; + + uint8_t ciphertext[16*16 + 9] = { + 0x64,0xa0,0x86,0x15,0x75,0x86,0x1a,0xf4,0x60,0xf0,0x62,0xc7,0x9b,0xe6,0x43,0xbd, + 0x5e,0x80,0x5c,0xfd,0x34,0x5c,0xf3,0x89,0xf1,0x08,0x67,0x0a,0xc7,0x6c,0x8c,0xb2, + 0x4c,0x6c,0xfc,0x18,0x75,0x5d,0x43,0xee,0xa0,0x9e,0xe9,0x4e,0x38,0x2d,0x26,0xb0, + 0xbd,0xb7,0xb7,0x3c,0x32,0x1b,0x01,0x00,0xd4,0xf0,0x3b,0x7f,0x35,0x58,0x94,0xcf, + 0x33,0x2f,0x83,0x0e,0x71,0x0b,0x97,0xce,0x98,0xc8,0xa8,0x4a,0xbd,0x0b,0x94,0x81, + 0x14,0xad,0x17,0x6e,0x00,0x8d,0x33,0xbd,0x60,0xf9,0x82,0xb1,0xff,0x37,0xc8,0x55, + 0x97,0x97,0xa0,0x6e,0xf4,0xf0,0xef,0x61,0xc1,0x86,0x32,0x4e,0x2b,0x35,0x06,0x38, + 0x36,0x06,0x90,0x7b,0x6a,0x7c,0x02,0xb0,0xf9,0xf6,0x15,0x7b,0x53,0xc8,0x67,0xe4, + 0xb9,0x16,0x6c,0x76,0x7b,0x80,0x4d,0x46,0xa5,0x9b,0x52,0x16,0xcd,0xe7,0xa4,0xe9, + 0x90,0x40,0xc5,0xa4,0x04,0x33,0x22,0x5e,0xe2,0x82,0xa1,0xb0,0xa0,0x6c,0x52,0x3e, + 0xaf,0x45,0x34,0xd7,0xf8,0x3f,0xa1,0x15,0x5b,0x00,0x47,0x71,0x8c,0xbc,0x54,0x6a, + 0x0d,0x07,0x2b,0x04,0xb3,0x56,0x4e,0xea,0x1b,0x42,0x22,0x73,0xf5,0x48,0x27,0x1a, + 0x0b,0xb2,0x31,0x60,0x53,0xfa,0x76,0x99,0x19,0x55,0xeb,0xd6,0x31,0x59,0x43,0x4e, + 0xce,0xbb,0x4e,0x46,0x6d,0xae,0x5a,0x10,0x73,0xa6,0x72,0x76,0x27,0x09,0x7a,0x10, + 0x49,0xe6,0x17,0xd9,0x1d,0x36,0x10,0x94,0xfa,0x68,0xf0,0xff,0x77,0x98,0x71,0x30, + 0x30,0x5b,0xea,0xba,0x2e,0xda,0x04,0xdf,0x99,0x7b,0x71,0x4d,0x6c,0x6f,0x2c,0x29, + 0xa6,0xad,0x5c,0xb4,0x02,0x2b,0x02,0x70,0x9b }; + + uint8_t aad[12] = { 0xf3,0x33,0x88,0x86,0x00,0x00,0x00,0x00,0x00,0x00,0x4e,0x91 }; + + uint8_t received_tag[16] = { 0xee,0xad,0x9d,0x67,0x89,0x0c,0xbb,0x22,0x39,0x23,0x36,0xfe,0xa1,0x85,0x1f,0x38 }; + + if(!AEAD_chacha20_poly1305(key,nonce,ciphertext,16*16+9,aad,12,received_tag,false)) + return false ; + } + std::cerr << " RFC7539 AEAD test vector #1 OK" << std::endl; return true; } From 88298b997e395350a46ef438d500c1efd8a546db Mon Sep 17 00:00:00 2001 From: mr-alice Date: Wed, 26 Oct 2016 14:45:21 +0200 Subject: [PATCH 09/52] added check for cleartext in AEAD test vector #1 --- libretroshare/src/crypto/chacha20.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/libretroshare/src/crypto/chacha20.cpp b/libretroshare/src/crypto/chacha20.cpp index 756bbdc32..c4298b200 100644 --- a/libretroshare/src/crypto/chacha20.cpp +++ b/libretroshare/src/crypto/chacha20.cpp @@ -1119,6 +1119,28 @@ bool perform_tests() if(!AEAD_chacha20_poly1305(key,nonce,ciphertext,16*16+9,aad,12,received_tag,false)) return false ; + + uint8_t cleartext[16*16+9] = { + 0x49,0x6e,0x74,0x65,0x72,0x6e,0x65,0x74,0x2d,0x44,0x72,0x61,0x66,0x74,0x73,0x20, + 0x61,0x72,0x65,0x20,0x64,0x72,0x61,0x66,0x74,0x20,0x64,0x6f,0x63,0x75,0x6d,0x65, + 0x6e,0x74,0x73,0x20,0x76,0x61,0x6c,0x69,0x64,0x20,0x66,0x6f,0x72,0x20,0x61,0x20, + 0x6d,0x61,0x78,0x69,0x6d,0x75,0x6d,0x20,0x6f,0x66,0x20,0x73,0x69,0x78,0x20,0x6d, + 0x6f,0x6e,0x74,0x68,0x73,0x20,0x61,0x6e,0x64,0x20,0x6d,0x61,0x79,0x20,0x62,0x65, + 0x20,0x75,0x70,0x64,0x61,0x74,0x65,0x64,0x2c,0x20,0x72,0x65,0x70,0x6c,0x61,0x63, + 0x65,0x64,0x2c,0x20,0x6f,0x72,0x20,0x6f,0x62,0x73,0x6f,0x6c,0x65,0x74,0x65,0x64, + 0x20,0x62,0x79,0x20,0x6f,0x74,0x68,0x65,0x72,0x20,0x64,0x6f,0x63,0x75,0x6d,0x65, + 0x6e,0x74,0x73,0x20,0x61,0x74,0x20,0x61,0x6e,0x79,0x20,0x74,0x69,0x6d,0x65,0x2e, + 0x20,0x49,0x74,0x20,0x69,0x73,0x20,0x69,0x6e,0x61,0x70,0x70,0x72,0x6f,0x70,0x72, + 0x69,0x61,0x74,0x65,0x20,0x74,0x6f,0x20,0x75,0x73,0x65,0x20,0x49,0x6e,0x74,0x65, + 0x72,0x6e,0x65,0x74,0x2d,0x44,0x72,0x61,0x66,0x74,0x73,0x20,0x61,0x73,0x20,0x72, + 0x65,0x66,0x65,0x72,0x65,0x6e,0x63,0x65,0x20,0x6d,0x61,0x74,0x65,0x72,0x69,0x61, + 0x6c,0x20,0x6f,0x72,0x20,0x74,0x6f,0x20,0x63,0x69,0x74,0x65,0x20,0x74,0x68,0x65, + 0x6d,0x20,0x6f,0x74,0x68,0x65,0x72,0x20,0x74,0x68,0x61,0x6e,0x20,0x61,0x73,0x20, + 0x2f,0xe2,0x80,0x9c,0x77,0x6f,0x72,0x6b,0x20,0x69,0x6e,0x20,0x70,0x72,0x6f,0x67, + 0x72,0x65,0x73,0x73,0x2e,0x2f,0xe2,0x80,0x9d } ; + + if(!constant_time_memory_compare(cleartext,ciphertext,16*16+9)) + return false ; } std::cerr << " RFC7539 AEAD test vector #1 OK" << std::endl; From c87ca67120d0bab0b70b3c1d29cc8491cbfb1043 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Wed, 26 Oct 2016 18:15:47 +0200 Subject: [PATCH 10/52] improved efficiency of AEAD --- libretroshare/src/crypto/chacha20.cpp | 201 +++++++++++++++----------- 1 file changed, 118 insertions(+), 83 deletions(-) diff --git a/libretroshare/src/crypto/chacha20.cpp b/libretroshare/src/crypto/chacha20.cpp index c4298b200..e13563c5a 100644 --- a/libretroshare/src/crypto/chacha20.cpp +++ b/libretroshare/src/crypto/chacha20.cpp @@ -34,6 +34,7 @@ #include "crypto/chacha20.h" #include "util/rsprint.h" +#include "util/rsscopetimer.h" #define rotl(x,n) { x = (x << n) | (x >> (-n & 31)) ;} @@ -95,16 +96,26 @@ struct uint256_32 b[6] += u.b[6] + (b[5]>>32); b[7] += u.b[7] + (b[6]>>32); - b[0] &= 0xffffffff; - b[1] &= 0xffffffff; - b[2] &= 0xffffffff; - b[3] &= 0xffffffff; - b[4] &= 0xffffffff; - b[5] &= 0xffffffff; - b[6] &= 0xffffffff; - b[7] &= 0xffffffff; + b[0] = (uint32_t) b[0]; + b[1] = (uint32_t) b[1]; + b[2] = (uint32_t) b[2]; + b[3] = (uint32_t) b[3]; + b[4] = (uint32_t) b[4]; + b[5] = (uint32_t) b[5]; + b[6] = (uint32_t) b[6]; + b[7] = (uint32_t) b[7]; + } + void operator -=(const uint256_32& u) + { + *this += ~u ; + ++(*this) ; + } + void operator++() + { + for(int i=0;i<8;++i) + if( (++b[i]) &= 0xffffffff) + break ; } - void operator -=(const uint256_32& u) { *this += ~u ; *this += uint256_32(0,0,0,0,0,0,0,1); } bool operator<(const uint256_32& u) const { @@ -191,37 +202,61 @@ struct uint256_32 for(int c=7;c>=0;--c) if(b[c] != 0) { - if( (b[c] & 0xff000000) != 0) return c*32 + 3*8 + max_non_zero_of_height_bits(b[c] >> 24) ; - if( (b[c] & 0x00ff0000) != 0) return c*32 + 2*8 + max_non_zero_of_height_bits(b[c] >> 16) ; - if( (b[c] & 0x0000ff00) != 0) return c*32 + 1*8 + max_non_zero_of_height_bits(b[c] >> 8) ; + if( (b[c] & 0xff000000) != 0) return (c<<5) + 3*8 + max_non_zero_of_height_bits(b[c] >> 24) ; + if( (b[c] & 0x00ff0000) != 0) return (c<<5) + 2*8 + max_non_zero_of_height_bits(b[c] >> 16) ; + if( (b[c] & 0x0000ff00) != 0) return (c<<5) + 1*8 + max_non_zero_of_height_bits(b[c] >> 8) ; return c*32 + 0*8 + max_non_zero_of_height_bits(b[c]) ; } return -1; } - void lshift() + void lshift(uint32_t n) { - int r = 0 ; + uint32_t p = n >> 5; // n/32 + uint32_t u = n & 0x1f ; // n%32 + if(p > 0) + for(int i=7;i>=0;--i) + b[i] = (i>=p)?b[i-p]:0 ; + + uint32_t r = 0 ; + + if(u>0) for(int i=0;i<8;++i) { - uint32_t r1 = (b[i] >> 31) ; - b[i] = (b[i] << 1) & 0xffffffff; + uint32_t r1 = (b[i] >> (31-u+1)) ; + b[i] = (b[i] << u) & 0xffffffff; b[i] += r ; r = r1 ; } } + void lshift() + { + uint32_t r ; + uint32_t r1 ; + + r1 = (b[0] >> 31) ; b[0] = (b[0] << 1) & 0xffffffff; r = r1 ; + r1 = (b[1] >> 31) ; b[1] = (b[1] << 1) & 0xffffffff; b[1] += r ; r = r1 ; + r1 = (b[2] >> 31) ; b[2] = (b[2] << 1) & 0xffffffff; b[2] += r ; r = r1 ; + r1 = (b[3] >> 31) ; b[3] = (b[3] << 1) & 0xffffffff; b[3] += r ; r = r1 ; + r1 = (b[4] >> 31) ; b[4] = (b[4] << 1) & 0xffffffff; b[4] += r ; r = r1 ; + r1 = (b[5] >> 31) ; b[5] = (b[5] << 1) & 0xffffffff; b[5] += r ; r = r1 ; + r1 = (b[6] >> 31) ; b[6] = (b[6] << 1) & 0xffffffff; b[6] += r ; r = r1 ; + b[7] = (b[7] << 1) & 0xffffffff; b[7] += r ; + } void rshift() { - uint32_t r = 0 ; + uint32_t r ; + uint32_t r1 ; - for(int i=7;i>=0;--i) - { - uint32_t r1 = b[i] & 0x1; - b[i] >>= 1 ; - b[i] += r << 31; - r = r1 ; - } + r1 = b[7] & 0x1; b[7] >>= 1 ; r = r1 ; + r1 = b[6] & 0x1; b[6] >>= 1 ; if(r) b[6] += 0x80000000 ; r = r1 ; + r1 = b[5] & 0x1; b[5] >>= 1 ; if(r) b[5] += 0x80000000 ; r = r1 ; + r1 = b[4] & 0x1; b[4] >>= 1 ; if(r) b[4] += 0x80000000 ; r = r1 ; + r1 = b[3] & 0x1; b[3] >>= 1 ; if(r) b[3] += 0x80000000 ; r = r1 ; + r1 = b[2] & 0x1; b[2] >>= 1 ; if(r) b[2] += 0x80000000 ; r = r1 ; + r1 = b[1] & 0x1; b[1] >>= 1 ; if(r) b[1] += 0x80000000 ; r = r1 ; + b[0] >>= 1 ; if(r) b[0] += 0x80000000 ; } }; @@ -236,11 +271,12 @@ static void quotient(const uint256_32& n,const uint256_32& p,uint256_32& q,uint2 int bmax = n.max_non_zero_bit() - p.max_non_zero_bit(); - uint256_32 m(0,0,0,0,0,0,0,1) ; + uint256_32 m(0,0,0,0,0,0,0,0) ; uint256_32 d = p ; - for(int i=0;i=0;--b,d.rshift(),m.rshift()) if(! (r < d)) @@ -249,6 +285,20 @@ static void quotient(const uint256_32& n,const uint256_32& p,uint256_32& q,uint2 q += m ; } } +static void remainder(const uint256_32& n,const uint256_32& p,uint256_32& r) +{ + // simple algorithm: add up multiples of u while keeping below *this. Once done, substract. + + r = n ; + int bmax = n.max_non_zero_bit() - p.max_non_zero_bit(); + + uint256_32 d = p ; + d.lshift(bmax); + + for(int b=bmax;b>=0;--b,d.rshift()) + if(! (r < d)) + r -= d ; +} class chacha20_state { @@ -308,6 +358,7 @@ static void apply_20_rounds(chacha20_state& s) add(s,t) ; } +#ifdef DEBUG_CHACHA20 static void print(const chacha20_state& s) { fprintf(stdout,"%08x %08x %08x %08x\n",s.c[0 ],s.c[1 ],s.c[2 ],s.c[3 ]) ; @@ -315,61 +366,7 @@ static void print(const chacha20_state& s) fprintf(stdout,"%08x %08x %08x %08x\n",s.c[8 ],s.c[9 ],s.c[10],s.c[11]) ; fprintf(stdout,"%08x %08x %08x %08x\n",s.c[12],s.c[13],s.c[14],s.c[15]) ; } - -// static uint8_t read16bits(char s) -// { -// if(s >= '0' && s <= '9') -// return s - '0' ; -// else if(s >= 'a' && s <= 'f') -// return s - 'a' + 10 ; -// else if(s >= 'A' && s <= 'F') -// return s - 'A' + 10 ; -// else -// throw std::runtime_error("Not an hex string!") ; -// } -// -// static uint256_32 create_256bit_int(const std::string& s) -// { -// uint256_32 r(0,0,0,0,0,0,0,0) ; -// -// fprintf(stdout,"Scanning %s\n",s.c_str()) ; -// -// for(int i=0;i<(int)s.length();++i) -// { -// uint32_t byte = (s.length() -1 - i)/2 ; -// uint32_t p = byte/4 ; -// uint32_t val; -// -// if(p >= 8) -// continue ; -// -// val = read16bits(s[i]) ; -// -// r.b[p] |= (( (val << (( (s.length()-i+1)%2)*4))) << (8*byte)) ; -// } -// -// return r; -// } -// static uint256_32 create_256bit_int_from_serialized(const std::string& s) -// { -// uint256_32 r(0,0,0,0,0,0,0,0) ; -// -// fprintf(stdout,"Scanning %s\n",s.c_str()) ; -// -// for(int i=0;i<(int)s.length();i+=3) -// { -// int byte = i/3 ; -// int p = byte/4 ; -// int sub_byte = byte - 4*p ; -// -// uint8_t b1 = read16bits(s[i+0]) ; -// uint8_t b2 = read16bits(s[i+1]) ; -// uint32_t b = (b1 << 4) + b2 ; -// -// r.b[p] |= ( b << (8*sub_byte)) ; -// } -// return r ; -// } +#endif void chacha20_encrypt(uint8_t key[32], uint32_t block_counter, uint8_t nonce[12], uint8_t *data, uint32_t size) { @@ -449,7 +446,7 @@ static void poly1305_add(poly1305_state& s,uint8_t *message,uint32_t size,bool p s.a *= s.r ; uint256_32 q,rst; - quotient(s.a,s.p,q,rst) ; + remainder(s.a,s.p,rst) ; s.a = rst ; } } @@ -646,6 +643,13 @@ bool perform_tests() std::cerr << " OK" << std::endl; + // operators + + { uint256_32 uu(0,0,0,0,0,0,0,0 ) ; ++uu ; if(!(uu == uint256_32(0,0,0,0,0,0,0,1))) return false ; } + { uint256_32 uu(0,0,0,0,0,0,0,0xffffffff) ; ++uu ; if(!(uu == uint256_32(0,0,0,0,0,0,1,0))) return false ; } + + std::cerr << " operator++ on 256bits numbers OK" << std::endl; + // sums/diffs of numbers for(uint32_t i=0;i<100;++i) @@ -1144,6 +1148,37 @@ bool perform_tests() } std::cerr << " RFC7539 AEAD test vector #1 OK" << std::endl; + // bandwidth test + // + + { + uint32_t SIZE = 1*1024*1024 ; + uint8_t *ten_megabyte_data = (uint8_t*)malloc(SIZE) ; + + uint8_t key[32] = { 0x1c,0x92,0x40,0xa5,0xeb,0x55,0xd3,0x8a,0xf3,0x33,0x88,0x86,0x04,0xf6,0xb5,0xf0, + 0x47,0x39,0x17,0xc1,0x40,0x2b,0x80,0x09,0x9d,0xca,0x5c,0xbc,0x20,0x70,0x75,0xc0 }; + + uint8_t nonce[12] = { 0x00,0x00,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08 }; + uint8_t aad[12] = { 0xf3,0x33,0x88,0x86,0x00,0x00,0x00,0x00,0x00,0x00,0x4e,0x91 }; + + uint8_t received_tag[16] ; + + { + RsScopeTimer s("AEAD") ; + chacha20_encrypt(key, 1, nonce, ten_megabyte_data,SIZE) ; + + std::cerr << " Chacha20 encryption speed: " << SIZE / (1024.0*1024.0) / s.duration() << " MB/s" << std::endl; + } + { + RsScopeTimer s("AEAD") ; + AEAD_chacha20_poly1305(key,nonce,ten_megabyte_data,SIZE,aad,12,received_tag,true) ; + + std::cerr << " AEAD encryption speed: " << SIZE / (1024.0*1024.0) / s.duration() << " MB/s" << std::endl; + } + + free(ten_megabyte_data) ; + } + return true; } From 848634636830d9829df75d6fa07bd8f77d9c3a9a Mon Sep 17 00:00:00 2001 From: mr-alice Date: Wed, 26 Oct 2016 22:05:56 +0200 Subject: [PATCH 11/52] added new encryption/authentication format AEAD_chacha20_sha256 --- libretroshare/src/crypto/chacha20.cpp | 144 ++++++++++++++++---------- libretroshare/src/crypto/chacha20.h | 22 +++- libretroshare/src/ft/ftserver.cc | 38 +++++-- 3 files changed, 140 insertions(+), 64 deletions(-) diff --git a/libretroshare/src/crypto/chacha20.cpp b/libretroshare/src/crypto/chacha20.cpp index e13563c5a..58b06d660 100644 --- a/libretroshare/src/crypto/chacha20.cpp +++ b/libretroshare/src/crypto/chacha20.cpp @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include #include @@ -38,6 +40,8 @@ #define rotl(x,n) { x = (x << n) | (x >> (-n & 31)) ;} +//#define DEBUG_CHACHA20 + namespace librs { namespace crypto { @@ -47,9 +51,9 @@ namespace crypto { */ struct uint256_32 { - uint64_t b[8] ; + uint32_t b[8] ; - uint256_32() { memset(&b[0],0,8*sizeof(uint64_t)) ; } + uint256_32() { memset(&b[0],0,8*sizeof(uint32_t)) ; } uint256_32(uint32_t b7,uint32_t b6,uint32_t b5,uint32_t b4,uint32_t b3,uint32_t b2,uint32_t b1,uint32_t b0) { @@ -87,33 +91,26 @@ struct uint256_32 // void operator +=(const uint256_32& u) { - b[0] += u.b[0]; - b[1] += u.b[1] + (b[0]>>32); - b[2] += u.b[2] + (b[1]>>32); - b[3] += u.b[3] + (b[2]>>32); - b[4] += u.b[4] + (b[3]>>32); - b[5] += u.b[5] + (b[4]>>32); - b[6] += u.b[6] + (b[5]>>32); - b[7] += u.b[7] + (b[6]>>32); + uint64_t v(0) ; - b[0] = (uint32_t) b[0]; - b[1] = (uint32_t) b[1]; - b[2] = (uint32_t) b[2]; - b[3] = (uint32_t) b[3]; - b[4] = (uint32_t) b[4]; - b[5] = (uint32_t) b[5]; - b[6] = (uint32_t) b[6]; - b[7] = (uint32_t) b[7]; + v += (uint64_t)b[0] + (uint64_t)u.b[0] ; b[0] = (uint32_t)v ; v >>= 32; + v += (uint64_t)b[1] + (uint64_t)u.b[1] ; b[1] = (uint32_t)v ; v >>= 32; + v += (uint64_t)b[2] + (uint64_t)u.b[2] ; b[2] = (uint32_t)v ; v >>= 32; + v += (uint64_t)b[3] + (uint64_t)u.b[3] ; b[3] = (uint32_t)v ; v >>= 32; + v += (uint64_t)b[4] + (uint64_t)u.b[4] ; b[4] = (uint32_t)v ; v >>= 32; + v += (uint64_t)b[5] + (uint64_t)u.b[5] ; b[5] = (uint32_t)v ; v >>= 32; + v += (uint64_t)b[6] + (uint64_t)u.b[6] ; b[6] = (uint32_t)v ; v >>= 32; + v += (uint64_t)b[7] + (uint64_t)u.b[7] ; b[7] = (uint32_t)v ; } void operator -=(const uint256_32& u) { *this += ~u ; - ++(*this) ; + ++*this ; } void operator++() { for(int i=0;i<8;++i) - if( (++b[i]) &= 0xffffffff) + if( ++b[i] ) break ; } @@ -132,14 +129,14 @@ struct uint256_32 { uint256_32 r(*this) ; - r.b[0] = (~b[0]) & 0xffffffff ; - r.b[1] = (~b[1]) & 0xffffffff ; - r.b[2] = (~b[2]) & 0xffffffff ; - r.b[3] = (~b[3]) & 0xffffffff ; - r.b[4] = (~b[4]) & 0xffffffff ; - r.b[5] = (~b[5]) & 0xffffffff ; - r.b[6] = (~b[6]) & 0xffffffff ; - r.b[7] = (~b[7]) & 0xffffffff ; + r.b[0] = ~b[0] ; + r.b[1] = ~b[1] ; + r.b[2] = ~b[2] ; + r.b[3] = ~b[3] ; + r.b[4] = ~b[4] ; + r.b[5] = ~b[5] ; + r.b[6] = ~b[6] ; + r.b[7] = ~b[7] ; return r ; } @@ -161,7 +158,7 @@ struct uint256_32 for(int j=0;j<8;++j) if(i+j < 8) { - uint64_t s = u.b[j]*b[i] ; + uint64_t s = (uint64_t)u.b[j]*(uint64_t)b[i] ; uint256_32 partial ; partial.b[i+j] = (s & 0xffffffff) ; @@ -172,17 +169,6 @@ struct uint256_32 r += partial; } *this = r; - -#ifdef DEBUG_CHACHA20 - if(!(!(b[0] & 0xffffffff00000000))) throw() ; - if(!(!(b[1] & 0xffffffff00000000))) throw() ; - if(!(!(b[2] & 0xffffffff00000000))) throw() ; - if(!(!(b[3] & 0xffffffff00000000))) throw() ; - if(!(!(b[4] & 0xffffffff00000000))) throw() ; - if(!(!(b[5] & 0xffffffff00000000))) throw() ; - if(!(!(b[6] & 0xffffffff00000000))) throw() ; - if(!(!(b[7] & 0xffffffff00000000))) throw() ; -#endif } static void print(const uint256_32& s) @@ -217,7 +203,7 @@ struct uint256_32 if(p > 0) for(int i=7;i>=0;--i) - b[i] = (i>=p)?b[i-p]:0 ; + b[i] = (i>=(int)p)?b[i-p]:0 ; uint32_t r = 0 ; @@ -235,14 +221,14 @@ struct uint256_32 uint32_t r ; uint32_t r1 ; - r1 = (b[0] >> 31) ; b[0] = (b[0] << 1) & 0xffffffff; r = r1 ; - r1 = (b[1] >> 31) ; b[1] = (b[1] << 1) & 0xffffffff; b[1] += r ; r = r1 ; - r1 = (b[2] >> 31) ; b[2] = (b[2] << 1) & 0xffffffff; b[2] += r ; r = r1 ; - r1 = (b[3] >> 31) ; b[3] = (b[3] << 1) & 0xffffffff; b[3] += r ; r = r1 ; - r1 = (b[4] >> 31) ; b[4] = (b[4] << 1) & 0xffffffff; b[4] += r ; r = r1 ; - r1 = (b[5] >> 31) ; b[5] = (b[5] << 1) & 0xffffffff; b[5] += r ; r = r1 ; - r1 = (b[6] >> 31) ; b[6] = (b[6] << 1) & 0xffffffff; b[6] += r ; r = r1 ; - b[7] = (b[7] << 1) & 0xffffffff; b[7] += r ; + r1 = (b[0] >> 31) ; b[0] <<= 1; r = r1 ; + r1 = (b[1] >> 31) ; b[1] <<= 1; b[1] += r ; r = r1 ; + r1 = (b[2] >> 31) ; b[2] <<= 1; b[2] += r ; r = r1 ; + r1 = (b[3] >> 31) ; b[3] <<= 1; b[3] += r ; r = r1 ; + r1 = (b[4] >> 31) ; b[4] <<= 1; b[4] += r ; r = r1 ; + r1 = (b[5] >> 31) ; b[5] <<= 1; b[5] += r ; r = r1 ; + r1 = (b[6] >> 31) ; b[6] <<= 1; b[6] += r ; r = r1 ; + b[7] <<= 1; b[7] += r ; } void rshift() { @@ -538,6 +524,37 @@ bool AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uin } } +bool AEAD_chacha20_sha256(uint8_t key[32], uint8_t nonce[12], uint8_t *data, uint32_t data_size, uint8_t tag[16], bool encrypt) +{ + // encrypt + tag. See RFC7539-2.8 + + if(encrypt) + { + chacha20_encrypt(key,1,nonce,data,data_size); + + uint8_t computed_tag[EVP_MAX_MD_SIZE]; + unsigned int md_size ; + HMAC(EVP_sha256(),key,32,data,data_size,computed_tag,&md_size) ; + + memcpy(tag,computed_tag,16) ; + + return true ; + } + else + { + uint8_t computed_tag[EVP_MAX_MD_SIZE]; + unsigned int md_size ; + HMAC(EVP_sha256(),key,32,data,data_size,computed_tag,&md_size) ; + + // decrypt + + chacha20_encrypt(key,1,nonce,data,data_size); + + return constant_time_memory_compare(tag,computed_tag,16) ; + } +} + + bool perform_tests() { // RFC7539 - 2.1.1 @@ -647,6 +664,7 @@ bool perform_tests() { uint256_32 uu(0,0,0,0,0,0,0,0 ) ; ++uu ; if(!(uu == uint256_32(0,0,0,0,0,0,0,1))) return false ; } { uint256_32 uu(0,0,0,0,0,0,0,0xffffffff) ; ++uu ; if(!(uu == uint256_32(0,0,0,0,0,0,1,0))) return false ; } + { uint256_32 uu(0,0,0,0,0,0,0,0) ; uu = ~uu;++uu ; if(!(uu == uint256_32(0,0,0,0,0,0,0,0))) return false ; } std::cerr << " operator++ on 256bits numbers OK" << std::endl; @@ -684,7 +702,19 @@ bool perform_tests() if(!(a == a)) return false ; if(!(c == a)) return false ; + + uint256_32 vv(0,0,0,0,0,0,0,1) ; + vv -= a ; + vv += a ; + + if(!(vv == uint256_32(0,0,0,0,0,0,0,1))) return false ; + } + uint256_32 vv(0,0,0,0,0,0,0,0) ; + uint256_32 ww(0,0,0,0,0,0,0,1) ; + vv -= ww ; + if(!(vv == ~uint256_32(0,0,0,0,0,0,0,0))) return false; + std::cerr << " Sums / diffs of 256bits numbers OK" << std::endl; // check that (a-b)*(c-d) = ac - bc - ad + bd @@ -753,7 +783,7 @@ bool perform_tests() quotient(n1,p1,q1,r1) ; #ifdef DEBUG_CHACHA20 - fprintf(stdout,"result: q=") ; chacha20::uint256_32::print(q1) ; fprintf(stdout," r=") ; chacha20::uint256_32::print(r1) ; fprintf(stdout,"\n") ; + fprintf(stdout,"result: q=") ; uint256_32::print(q1) ; fprintf(stdout," r=") ; uint256_32::print(r1) ; fprintf(stdout,"\n") ; #endif uint256_32 res(q1) ; @@ -1164,16 +1194,22 @@ bool perform_tests() uint8_t received_tag[16] ; { - RsScopeTimer s("AEAD") ; + RsScopeTimer s("AEAD1") ; chacha20_encrypt(key, 1, nonce, ten_megabyte_data,SIZE) ; - std::cerr << " Chacha20 encryption speed: " << SIZE / (1024.0*1024.0) / s.duration() << " MB/s" << std::endl; + std::cerr << " Chacha20 encryption speed : " << SIZE / (1024.0*1024.0) / s.duration() << " MB/s" << std::endl; } { - RsScopeTimer s("AEAD") ; + RsScopeTimer s("AEAD2") ; AEAD_chacha20_poly1305(key,nonce,ten_megabyte_data,SIZE,aad,12,received_tag,true) ; - std::cerr << " AEAD encryption speed: " << SIZE / (1024.0*1024.0) / s.duration() << " MB/s" << std::endl; + std::cerr << " AEAD/poly1305 encryption speed: " << SIZE / (1024.0*1024.0) / s.duration() << " MB/s" << std::endl; + } + { + RsScopeTimer s("AEAD3") ; + AEAD_chacha20_sha256(key,nonce,ten_megabyte_data,SIZE,received_tag,true) ; + + std::cerr << " AEAD/sha256 encryption speed : " << SIZE / (1024.0*1024.0) / s.duration() << " MB/s" << std::endl; } free(ten_megabyte_data) ; diff --git a/libretroshare/src/crypto/chacha20.h b/libretroshare/src/crypto/chacha20.h index d2668aea3..1e289d0b9 100644 --- a/libretroshare/src/crypto/chacha20.h +++ b/libretroshare/src/crypto/chacha20.h @@ -59,9 +59,11 @@ namespace librs * 16-padded AAD (additional authenticated data) and its size, authenticated using poly1305. * * \param key key that is used to derive a one time secret key for poly1305 and that is also used to encrypt the data - * \param nonce nonce. *Should be unique* in order to make the poly1305 key unique. - * \param data data that is encrypted. + * \param nonce nonce. *Should be unique* in order to make the chacha20 stream cipher unique. + * \param data data that is encrypted/decrypted in place. * \param size size of the data + * \param aad additional authenticated data. Can be used to authenticate the nonce. + * \param aad_size * \param tag generated poly1305 tag. * \param encrypt true to encrypt, false to decrypt and check the tag. * \return @@ -70,6 +72,22 @@ namespace librs */ bool AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint32_t data_size,uint8_t *aad,uint32_t aad_size,uint8_t tag[16],bool encrypt_or_decrypt) ; + /*! + * \brief AEAD_chacha20_sha256 + * Provides authenticated encryption using a simple construction that associates chacha20 encryption with HMAC authentication using + * the same 32 bytes key. The authenticated tag is the 16 first bytes of the sha256 HMAC. + * + * \param key encryption/authentication key + * \param nonce nonce. *Should be unique* in order to make chacha20 stream cipher unique. + * \param data data that is encrypted/decrypted in place + * \param data_size size of data to encrypt/authenticate + * \param tag 16 bytes authentication tag result + * \param encrypt true to encrypt, false to decrypt and check the tag. + * \return + * always true for encryption. + * authentication result for decryption. data is *always* xored to the cipher stream whatever the authentication result is. + */ + bool AEAD_chacha20_sha256(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint32_t data_size,uint8_t tag[16],bool encrypt); /*! * \brief constant_time_memcmp * Provides a constant time comparison of two memory chunks. Calls CRYPTO_memcmp. diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 3c88c6692..7478eef7a 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -1023,7 +1023,8 @@ bool ftServer::sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t // // // Encryption format: -// ae ad 00 01 : encryption using AEAD, format 00, version 01 +// ae ad 01 01 : encryption using AEAD, format 01 (authed with Poly1305 ), version 01 +// ae ad 02 01 : encryption using AEAD, format 02 (authed with HMAC Sha256), version 01 // // @@ -1045,6 +1046,10 @@ static const uint32_t ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE = 16 ; static const uint32_t ENCRYPTED_FT_HEADER_SIZE = 4 ; static const uint32_t ENCRYPTED_FT_EDATA_SIZE = 4 ; +static const uint8_t ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_POLY1305 = 0x01 ; +static const uint8_t ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_SHA256 = 0x02 ; + + bool ftServer::encryptItem(RsTurtleGenericTunnelItem *clear_item,const RsFileHash& hash,RsTurtleGenericDataItem *& encrypted_item) { uint8_t initialization_vector[ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE] ; @@ -1072,7 +1077,7 @@ bool ftServer::encryptItem(RsTurtleGenericTunnelItem *clear_item,const RsFileHas edata[0] = 0xae ; edata[1] = 0xad ; - edata[2] = 0x00 ; + edata[2] = ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_SHA256 ; // means AEAD_chacha20_sha256 edata[3] = 0x01 ; offset += ENCRYPTED_FT_HEADER_SIZE; @@ -1103,7 +1108,12 @@ bool ftServer::encryptItem(RsTurtleGenericTunnelItem *clear_item,const RsFileHas uint8_t encryption_key[32] ; deriveEncryptionKey(hash,encryption_key) ; - librs::crypto::AEAD_chacha20_poly1305(encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset],true) ; + if(edata[2] == ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_POLY1305) + librs::crypto::AEAD_chacha20_poly1305(encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset],true) ; + else if(edata[2] == ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_SHA256) + librs::crypto::AEAD_chacha20_sha256(encryption_key,initialization_vector,&edata[aad_offset],edata_size+ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE+ENCRYPTED_FT_EDATA_SIZE, &edata[authentication_tag_offset],true) ; + else + return false ; std::cerr << " encryption key : " << RsUtil::BinToHex(encryption_key,32) << std::endl; std::cerr << " authen. tag : " << RsUtil::BinToHex(&edata[authentication_tag_offset],ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE) << std::endl; @@ -1126,7 +1136,7 @@ bool ftServer::decryptItem(RsTurtleGenericDataItem *encrypted_item,const RsFileH if(edata[0] != 0xae) return false ; if(edata[1] != 0xad) return false ; - if(edata[2] != 0x00) return false ; + if(edata[2] != ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_POLY1305 && edata[2] != ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_SHA256) return false ; if(edata[3] != 0x01) return false ; offset += ENCRYPTED_FT_HEADER_SIZE ; @@ -1155,11 +1165,23 @@ bool ftServer::decryptItem(RsTurtleGenericDataItem *encrypted_item,const RsFileH uint32_t authentication_tag_offset = offset + edata_size ; std::cerr << " authen. tag : " << RsUtil::BinToHex(&edata[authentication_tag_offset],ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE) << std::endl; - if(!librs::crypto::AEAD_chacha20_poly1305(encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset],false)) - return false; + bool result ; - std::cerr << " authen. result : ok" << std::endl; - std::cerr << " decrypted daya : ok" << RsUtil::BinToHex(&edata[clear_item_offset],std::min(50u,edata_size)) << "(...)" << std::endl; + if(edata[2] == ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_POLY1305) + result = librs::crypto::AEAD_chacha20_poly1305(encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset],false) ; + else if(edata[2] == ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_SHA256) + result = librs::crypto::AEAD_chacha20_sha256(encryption_key,initialization_vector,&edata[aad_offset],edata_size+ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE+ENCRYPTED_FT_EDATA_SIZE, &edata[authentication_tag_offset],false) ; + else + return false ; + + std::cerr << " authen. result : " << result << std::endl; + std::cerr << " decrypted daya : " << RsUtil::BinToHex(&edata[clear_item_offset],std::min(50u,edata_size)) << "(...)" << std::endl; + + if(!result) + { + std::cerr << "(EE) decryption/authentication went wrong." << std::endl; + return false ; + } decrypted_item = deserialiseItem(&edata[clear_item_offset],edata_size) ; From babc126be39f495d14c7bd9f0a34efa4ad7839f5 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Sat, 29 Oct 2016 17:59:03 +0200 Subject: [PATCH 12/52] added default encryption policy variable and GUI to change it --- .../src/file_sharing/directory_storage.cc | 33 +++++++++--- .../src/file_sharing/directory_storage.h | 16 +++++- libretroshare/src/ft/ftcontroller.cc | 50 +++++++++++++++---- libretroshare/src/ft/ftcontroller.h | 1 + libretroshare/src/ft/ftserver.cc | 33 +++++++++++- libretroshare/src/ft/ftserver.h | 3 ++ libretroshare/src/retroshare/rsfiles.h | 8 ++- .../src/gui/settings/TransferPage.cpp | 48 ++++++++++++------ .../src/gui/settings/TransferPage.h | 1 + .../src/gui/settings/TransferPage.ui | 25 +++++++++- 10 files changed, 183 insertions(+), 35 deletions(-) diff --git a/libretroshare/src/file_sharing/directory_storage.cc b/libretroshare/src/file_sharing/directory_storage.cc index 9ec32487f..80944f46a 100644 --- a/libretroshare/src/file_sharing/directory_storage.cc +++ b/libretroshare/src/file_sharing/directory_storage.cc @@ -168,13 +168,6 @@ bool DirectoryStorage::updateHash(const EntryIndex& index,const RsFileHash& hash return mFileHierarchy->updateHash(index,hash); } -int DirectoryStorage::searchHash(const RsFileHash& hash, const RsFileHash& real_hash, EntryIndex& result) const -{ - RS_STACK_MUTEX(mDirStorageMtx) ; -#warning code needed here - return mFileHierarchy->searchHash(hash,result); -} - void DirectoryStorage::load(const std::string& local_file_name) { RS_STACK_MUTEX(mDirStorageMtx) ; @@ -296,6 +289,32 @@ bool DirectoryStorage::getIndexFromDirHash(const RsFileHash& hash,EntryIndex& in /* Local Directory Storage */ /******************************************************************************************************************/ +bool LocalDirectoryStorage::locked_findRealHash(const RsFileHash& hash, RsFileHash& real_hash) const +{ + std::map::const_iterator it = mEncryptedHashes.find(hash) ; + + if(it == mEncryptedHashes.end()) + return false ; + + real_hash = it->second ; + return true ; +} + +int LocalDirectoryStorage::searchHash(const RsFileHash& hash, RsFileHash& real_hash, EntryIndex& result) const +{ + RS_STACK_MUTEX(mDirStorageMtx) ; + + if(locked_findRealHash(hash,real_hash) && mFileHierarchy->searchHash(real_hash,result)) + return true ; + + if(mFileHierarchy->searchHash(hash,result)) + { + real_hash.clear(); + return true ; + } + return false ; +} + void LocalDirectoryStorage::setSharedDirectoryList(const std::list& lst) { RS_STACK_MUTEX(mDirStorageMtx) ; diff --git a/libretroshare/src/file_sharing/directory_storage.h b/libretroshare/src/file_sharing/directory_storage.h index 653b1286d..b9c4a3ea0 100644 --- a/libretroshare/src/file_sharing/directory_storage.h +++ b/libretroshare/src/file_sharing/directory_storage.h @@ -53,7 +53,6 @@ class DirectoryStorage virtual int searchTerms(const std::list& terms, std::list &results) const ; virtual int searchBoolExp(RsRegularExpression::Expression * exp, std::list &results) const ; - virtual int searchHash(const RsFileHash& hash, const RsFileHash &real_hash, EntryIndex &results) const ; // gets/sets the various time stamps: // @@ -216,6 +215,19 @@ public: void updateShareFlags(const SharedDirInfo& info) ; bool convertSharedFilePath(const std::string& path_with_virtual_name,std::string& fullpath) ; + /*! + * \brief searchHash + * Looks into local database of shared files for the given hash. Also looks for files such that the hash of the hash + * matches the given hash, and returns the real hash. + * \param hash hash to look for + * \param real_hash hash such that H(real_hash) = hash, or null hash if not found. + * \param results Entry index of the file that is found + * \return + * true is a file is found + * false otherwise. + */ + virtual int searchHash(const RsFileHash& hash, RsFileHash &real_hash, EntryIndex &results) const ; + /*! * \brief updateTimeStamps * Checks recursive TS and update the if needed. @@ -261,6 +273,7 @@ public: bool serialiseDirEntry(const EntryIndex& indx, RsTlvBinaryData& bindata, const RsPeerId &client_id) ; private: + bool locked_findRealHash(const RsFileHash& hash, RsFileHash& real_hash) const; std::string locked_getVirtualPath(EntryIndex indx) const ; std::string locked_getVirtualDirName(EntryIndex indx) const ; @@ -268,6 +281,7 @@ private: std::string locked_findRealRootFromVirtualFilename(const std::string& virtual_rootdir) const; std::map mLocalDirs ; // map is better for search. it->first=it->second.filename + std::map mEncryptedHashes; // map such that hash(it->second) = it->first std::string mFileName; bool mTSChanged ; diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index ae90dfe50..a4faa5868 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -94,7 +94,7 @@ ftFileControl::ftFileControl(std::string fname, mTransfer(tm), mCreator(fc), mState(DOWNLOADING), mHash(hash), mSize(size), mFlags(flags), mCreateTime(0), mQueuePriority(0), mQueuePosition(0) { - return; + return; } ftController::ftController(ftDataMultiplex *dm, p3ServiceControl *sc, uint32_t ftServiceId) @@ -113,7 +113,8 @@ ftController::ftController(ftDataMultiplex *dm, p3ServiceControl *sc, uint32_t f { _max_active_downloads = 5 ; // default queue size _min_prioritized_transfers = 3 ; - /* TODO */ + mDefaultEncryptionPolicy = RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE; + /* TODO */ cnt = 0 ; } @@ -580,7 +581,7 @@ void ftController::locked_checkQueueElement(uint32_t pos) _queue[pos]->mState = ftFileControl::DOWNLOADING ; if(_queue[pos]->mFlags & RS_FILE_REQ_ANONYMOUS_ROUTING) - mTurtle->monitorTunnels(_queue[pos]->mHash,mFtServer,true) ; + mFtServer->activateTunnels(_queue[pos]->mHash,_queue[pos]->mFlags,true); } if(pos >= _max_active_downloads && _queue[pos]->mState != ftFileControl::QUEUED && _queue[pos]->mState != ftFileControl::PAUSED) @@ -589,8 +590,8 @@ void ftController::locked_checkQueueElement(uint32_t pos) _queue[pos]->mCreator->closeFile() ; if(_queue[pos]->mFlags & RS_FILE_REQ_ANONYMOUS_ROUTING) - mTurtle->stopMonitoringTunnels(_queue[pos]->mHash) ; - } + mFtServer->activateTunnels(_queue[pos]->mHash,_queue[pos]->mFlags,false); + } } bool ftController::FlagFileComplete(const RsFileHash& hash) @@ -835,7 +836,7 @@ bool ftController::completeFile(const RsFileHash& hash) mDownloads.erase(it); if(flags & RS_FILE_REQ_ANONYMOUS_ROUTING) - mTurtle->stopMonitoringTunnels(hash_to_suppress) ; + mFtServer->activateTunnels(hash_to_suppress,flags,false); } /******* UNLOCKED ********/ @@ -978,6 +979,17 @@ bool ftController::FileRequest(const std::string& fname, const RsFileHash& hash if(alreadyHaveFile(hash, info)) return false ; + if(mDefaultEncryptionPolicy == RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT) + { + flags |= RS_FILE_REQ_ENCRYPTED ; + flags &= ~RS_FILE_REQ_UNENCRYPTED ; + } + else + { + flags |= RS_FILE_REQ_ENCRYPTED ; + flags |= RS_FILE_REQ_UNENCRYPTED ; + } + if(size == 0) // we treat this special case because { /* if no destpath - send to download directory */ @@ -1174,7 +1186,7 @@ bool ftController::FileRequest(const std::string& fname, const RsFileHash& hash // We check that flags are consistent. if(flags & RS_FILE_REQ_ANONYMOUS_ROUTING) - mTurtle->monitorTunnels(hash,mFtServer,true) ; + mFtServer->activateTunnels(hash,flags,true); bool assume_availability = false; @@ -1275,7 +1287,7 @@ bool ftController::setChunkStrategy(const RsFileHash& hash,FileChunksInfo::Chunk bool ftController::FileCancel(const RsFileHash& hash) { - rsTurtle->stopMonitoringTunnels(hash) ; + mFtServer->activateTunnels(hash,TransferRequestFlags(0),false); #ifdef CONTROL_DEBUG std::cerr << "ftController::FileCancel" << std::endl; @@ -1813,6 +1825,7 @@ const std::string download_dir_ss("DOWN_DIR"); const std::string partial_dir_ss("PART_DIR"); const std::string default_chunk_strategy_ss("DEFAULT_CHUNK_STRATEGY"); const std::string free_space_limit_ss("FREE_SPACE_LIMIT"); +const std::string default_encryption_policy("DEFAULT_ENCRYPTION_POLICY"); /* p3Config Interface */ @@ -2102,7 +2115,26 @@ bool ftController::loadConfigMap(std::map &configMap) setPartialsDirectory(mit->second); } - if (configMap.end() != (mit = configMap.find(default_chunk_strategy_ss))) + if (configMap.end() != (mit = configMap.find(default_encryption_policy))) + { + if(mit->second == "STRICT") + { + mDefaultEncryptionPolicy = RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT ; + std::cerr << "Note: loading default value for encryption policy: STRICT" << std::endl; + } + else if(mit->second == "PERMISSIVE") + { + mDefaultEncryptionPolicy = RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE ; + std::cerr << "Note: loading default value for encryption policy: PERMISSIVE" << std::endl; + } + else + { + std::cerr << "(EE) encryption policy not recognized: \"" << mit->second << "\"" << std::endl; + mDefaultEncryptionPolicy = RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE ; + } + } + + if (configMap.end() != (mit = configMap.find(default_chunk_strategy_ss))) { if(mit->second == "STREAMING") { diff --git a/libretroshare/src/ft/ftcontroller.h b/libretroshare/src/ft/ftcontroller.h index 516b07050..6a7c380c9 100644 --- a/libretroshare/src/ft/ftcontroller.h +++ b/libretroshare/src/ft/ftcontroller.h @@ -237,6 +237,7 @@ class ftController: public RsTickingThread, public pqiServiceMonitor, public p3C ftServer *mFtServer ; p3ServiceControl *mServiceCtrl; uint32_t mFtServiceId; + uint32_t mDefaultEncryptionPolicy ; uint32_t cnt ; RsMutex ctrlMutex; diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 7478eef7a..f68b7813b 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -250,6 +250,26 @@ bool ftServer::FileRequest(const std::string& fname, const RsFileHash& hash, uin return true ; } +bool ftServer::activateTunnels(const RsFileHash& hash,TransferRequestFlags flags,bool onoff) +{ + RsFileHash hash_of_hash ; + + encryptHash(hash,hash_of_hash) ; + mEncryptedHashes.insert(std::make_pair(hash_of_hash,hash)) ; + + if(onoff) + { + if(flags & RS_FILE_REQ_ENCRYPTED) mTurtleRouter->monitorTunnels(hash_of_hash,this,true) ; + if(flags & RS_FILE_REQ_UNENCRYPTED) mTurtleRouter->monitorTunnels(hash,this,true) ; + } + else + { + mTurtleRouter->stopMonitoringTunnels(hash_of_hash); + mTurtleRouter->stopMonitoringTunnels(hash); + } + return true ; +} + bool ftServer::setDestinationName(const RsFileHash& hash,const std::string& name) { return mFtController->setDestinationName(hash,name); @@ -462,7 +482,12 @@ bool ftServer::handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_i FileInfo info ; bool res = FileDetails(hash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY, info); -#warning need code here => turn H(H) into real hash + if(info.transfer_info_flags & RS_FILE_REQ_ENCRYPTED) + { + std::cerr << "handleTunnelRequest: openning encrypted FT tunnel for H(H(F))=" << hash << " and H(F)=" << info.hash << std::endl; + mEncryptedHashes[info.hash] = hash ; + } +#warning needs to tweak for swarming with encrypted FT if( (!res) && FileDetails(hash,RS_FILE_HINTS_DOWNLOAD,info)) { // This file is currently being downloaded. Let's look if we already have a chunk or not. If not, no need to @@ -1191,6 +1216,12 @@ bool ftServer::decryptItem(RsTurtleGenericDataItem *encrypted_item,const RsFileH return true ; } +bool ftServer::encryptHash(const RsFileHash& hash, RsFileHash& hash_of_hash) +{ + hash_of_hash = RsDirUtil::sha1sum(hash.toByteArray(),hash.SIZE_IN_BYTES); + return true ; +} + bool ftServer::findRealHash(const RsFileHash& hash, RsFileHash& real_hash) { std::map::const_iterator it = mEncryptedHashes.find(hash) ; diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index 4f36aad91..ef752dc85 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -217,6 +217,8 @@ public: /*************** Data Transfer Interface ***********************/ /***************************************************************/ public: + virtual bool activateTunnels(const RsFileHash& hash,TransferRequestFlags flags,bool onoff); + virtual bool sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data); virtual bool sendDataRequest(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize); virtual bool sendChunkMapRequest(const RsPeerId& peer_id,const RsFileHash& hash,bool is_client) ; @@ -255,6 +257,7 @@ protected: // fnds out what is the real hash of encrypted hash hash bool findRealHash(const RsFileHash& hash, RsFileHash& real_hash); + bool encryptHash(const RsFileHash& hash, RsFileHash& hash_of_hash); private: diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index b9f7a69be..18036c52a 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -43,6 +43,9 @@ const uint32_t RS_FILE_CTRL_PAUSE = 0x00000100; const uint32_t RS_FILE_CTRL_START = 0x00000200; const uint32_t RS_FILE_CTRL_FORCE_CHECK = 0x00000400; +const uint32_t RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT = 0x00000001 ; +const uint32_t RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE = 0x00000002 ; + const uint32_t RS_FILE_RATE_TRICKLE = 0x00000001; const uint32_t RS_FILE_RATE_SLOW = 0x00000002; const uint32_t RS_FILE_RATE_STANDARD = 0x00000003; @@ -79,6 +82,7 @@ const FileSearchFlags RS_FILE_HINTS_PERMISSION_MASK ( 0x00000180 );// OR // const TransferRequestFlags RS_FILE_REQ_ANONYMOUS_ROUTING ( 0x00000040 ); // Use to ask turtle router to download the file. const TransferRequestFlags RS_FILE_REQ_ENCRYPTED ( 0x00000080 ); // Asks for end-to-end encryption of file at the level of ftServer +const TransferRequestFlags RS_FILE_REQ_UNENCRYPTED ( 0x00000100 ); // Asks for no end-to-end encryption of file at the level of ftServer const TransferRequestFlags RS_FILE_REQ_ASSUME_AVAILABILITY ( 0x00000200 ); // Assume full source availability. Used for cache files. const TransferRequestFlags RS_FILE_REQ_CACHE_deprecated ( 0x00000400 ); // Old stuff used for cache files. Not used anymore. const TransferRequestFlags RS_FILE_REQ_EXTRA ( 0x00000800 ); @@ -86,7 +90,7 @@ const TransferRequestFlags RS_FILE_REQ_MEDIA ( 0x00001000 ); const TransferRequestFlags RS_FILE_REQ_BACKGROUND ( 0x00002000 ); // To download slowly. const TransferRequestFlags RS_FILE_REQ_NO_SEARCH ( 0x02000000 ); // disable searching for potential direct sources. -// const uint32_t RS_FILE_HINTS_SHARE_FLAGS_MASK = RS_FILE_HINTS_NETWORK_WIDE_OTHERS | RS_FILE_HINTS_BROWSABLE_OTHERS +// const uint32_t RS_FILE_HINTS_SHARE_FLAGS_MASK = RS_FILE_HINTS_NETWORK_WIDE_OTHERS | RS_FILE_HINTS_BROWSABLE_OTHERS // | RS_FILE_HINTS_NETWORK_WIDE_GROUPS | RS_FILE_HINTS_BROWSABLE_GROUPS ; /* Callback Codes */ @@ -142,6 +146,8 @@ class RsFiles virtual void setFreeDiskSpaceLimit(uint32_t size_in_mb) =0; virtual bool FileControl(const RsFileHash& hash, uint32_t flags) = 0; virtual bool FileClearCompleted() = 0; + virtual void setDefaultEncryptionPolicy(uint32_t policy)=0 ; // RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT/PERMISSIVE + virtual uint32_t defaultEncryptionPolicy()=0 ; /*** * Control of Downloads Priority. diff --git a/retroshare-gui/src/gui/settings/TransferPage.cpp b/retroshare-gui/src/gui/settings/TransferPage.cpp index bccdcea3c..c30d6ebfd 100644 --- a/retroshare-gui/src/gui/settings/TransferPage.cpp +++ b/retroshare-gui/src/gui/settings/TransferPage.cpp @@ -32,24 +32,31 @@ TransferPage::TransferPage(QWidget * parent, Qt::WindowFlags flags) : ConfigPage(parent, flags) { - /* Invoke the Qt Designer generated object setup routine */ - ui.setupUi(this); + /* Invoke the Qt Designer generated object setup routine */ + ui.setupUi(this); - ui._queueSize_SB->setValue(rsFiles->getQueueSize()) ; + ui._queueSize_SB->setValue(rsFiles->getQueueSize()) ; - switch(rsFiles->defaultChunkStrategy()) - { - case FileChunksInfo::CHUNK_STRATEGY_STREAMING: ui._defaultStrategy_CB->setCurrentIndex(0) ; break ; - case FileChunksInfo::CHUNK_STRATEGY_PROGRESSIVE: ui._defaultStrategy_CB->setCurrentIndex(1) ; break ; - case FileChunksInfo::CHUNK_STRATEGY_RANDOM: ui._defaultStrategy_CB->setCurrentIndex(2) ; break ; - } + switch(rsFiles->defaultChunkStrategy()) + { + case FileChunksInfo::CHUNK_STRATEGY_STREAMING: ui._defaultStrategy_CB->setCurrentIndex(0) ; break ; + case FileChunksInfo::CHUNK_STRATEGY_PROGRESSIVE: ui._defaultStrategy_CB->setCurrentIndex(1) ; break ; + case FileChunksInfo::CHUNK_STRATEGY_RANDOM: ui._defaultStrategy_CB->setCurrentIndex(2) ; break ; + } - ui._diskSpaceLimit_SB->setValue(rsFiles->freeDiskSpaceLimit()) ; + switch(rsFiles->defaultEncryptionPolicy()) + { + case RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE: ui._e2e_encryption_CB->setCurrentIndex(0) ; break ; + case RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT : ui._e2e_encryption_CB->setCurrentIndex(1) ; break ; + } - QObject::connect(ui._queueSize_SB,SIGNAL(valueChanged(int)),this,SLOT(updateQueueSize(int))) ; - QObject::connect(ui._defaultStrategy_CB,SIGNAL(activated(int)),this,SLOT(updateDefaultStrategy(int))) ; - QObject::connect(ui._diskSpaceLimit_SB,SIGNAL(valueChanged(int)),this,SLOT(updateDiskSizeLimit(int))) ; - QObject::connect(ui._max_tr_up_per_sec_SB, SIGNAL( valueChanged( int ) ), this, SLOT( updateMaxTRUpRate(int) ) ); + ui._diskSpaceLimit_SB->setValue(rsFiles->freeDiskSpaceLimit()) ; + + QObject::connect(ui._queueSize_SB,SIGNAL(valueChanged(int)),this,SLOT(updateQueueSize(int))) ; + QObject::connect(ui._defaultStrategy_CB,SIGNAL(activated(int)),this,SLOT(updateDefaultStrategy(int))) ; + QObject::connect(ui._e2e_encryption_CB,SIGNAL(activated(int)),this,SLOT(updateEncryptionPolicy(int))) ; + QObject::connect(ui._diskSpaceLimit_SB,SIGNAL(valueChanged(int)),this,SLOT(updateDiskSizeLimit(int))) ; + QObject::connect(ui._max_tr_up_per_sec_SB, SIGNAL( valueChanged( int ) ), this, SLOT( updateMaxTRUpRate(int) ) ); ui._max_tr_up_per_sec_SB->setValue(rsTurtle->getMaxTRForwardRate()) ; } @@ -57,6 +64,19 @@ void TransferPage::updateMaxTRUpRate(int b) { rsTurtle->setMaxTRForwardRate(b) ; } + +void TransferPage::updateEncryptionPolicy(int b) +{ + switch(b) + { + case 1: rsFiles->setDefaultEncryptionPolicy(RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT) ; + break ; + default: + case 0: rsFiles->setDefaultEncryptionPolicy(RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE) ; + break ; + } +} + void TransferPage::updateDefaultStrategy(int i) { switch(i) diff --git a/retroshare-gui/src/gui/settings/TransferPage.h b/retroshare-gui/src/gui/settings/TransferPage.h index 373d9a17f..75cab1b4c 100644 --- a/retroshare-gui/src/gui/settings/TransferPage.h +++ b/retroshare-gui/src/gui/settings/TransferPage.h @@ -49,6 +49,7 @@ class TransferPage: public ConfigPage void updateDefaultStrategy(int) ; void updateDiskSizeLimit(int) ; void updateMaxTRUpRate(int); + void updateEncryptionPolicy(int); private: diff --git a/retroshare-gui/src/gui/settings/TransferPage.ui b/retroshare-gui/src/gui/settings/TransferPage.ui index ceeae7f47..88f8a3730 100644 --- a/retroshare-gui/src/gui/settings/TransferPage.ui +++ b/retroshare-gui/src/gui/settings/TransferPage.ui @@ -6,8 +6,8 @@ 0 0 - 700 - 356 + 741 + 372 @@ -49,6 +49,13 @@ + + + + End-to-end encryption: + + + @@ -135,6 +142,20 @@ + + + + + Accepted + + + + + Enforced + + + + From d843c1c1a64bf8424bfc7ce858e056f2cb1ee657 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Sat, 29 Oct 2016 18:18:02 +0200 Subject: [PATCH 13/52] put consts behind serial_size() and serialise() in turtle items and ft items --- libretroshare/src/ft/ftcontroller.cc | 13 ++++++++- libretroshare/src/ft/ftcontroller.h | 4 ++- libretroshare/src/ft/ftserver.cc | 8 +++++ libretroshare/src/ft/ftserver.h | 3 +- .../src/ft/ftturtlefiletransferitem.cc | 24 +++++++-------- .../src/ft/ftturtlefiletransferitem.h | 24 +++++++-------- libretroshare/src/turtle/rsturtleitem.cc | 24 +++++++-------- libretroshare/src/turtle/rsturtleitem.h | 29 +++++++++---------- 8 files changed, 75 insertions(+), 54 deletions(-) diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index a4faa5868..91e0c0dd9 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -2167,7 +2167,18 @@ bool ftController::loadConfigMap(std::map &configMap) return true; } -void ftController::setFreeDiskSpaceLimit(uint32_t size_in_mb) +void ftController::setDefaultEncryptionPolicy(uint32_t p) +{ + RsStackMutex stack(ctrlMutex); /******* LOCKED ********/ + mDefaultEncryptionPolicy = p ; + IndicateConfigChanged(); +} +uint32_t ftController::defaultEncryptionPolicy() +{ + RsStackMutex stack(ctrlMutex); /******* LOCKED ********/ + return mDefaultEncryptionPolicy ; +} +void ftController::setFreeDiskSpaceLimit(uint32_t size_in_mb) { RsDiscSpace::setFreeSpaceLimit(size_in_mb) ; diff --git a/libretroshare/src/ft/ftcontroller.h b/libretroshare/src/ft/ftcontroller.h index 6a7c380c9..c1ea26d0a 100644 --- a/libretroshare/src/ft/ftcontroller.h +++ b/libretroshare/src/ft/ftcontroller.h @@ -140,9 +140,11 @@ class ftController: public RsTickingThread, public pqiServiceMonitor, public p3C bool setChunkStrategy(const RsFileHash& hash,FileChunksInfo::ChunkStrategy s); void setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy s); - FileChunksInfo::ChunkStrategy defaultChunkStrategy(); + void setDefaultEncryptionPolicy(uint32_t s); + FileChunksInfo::ChunkStrategy defaultChunkStrategy(); uint32_t freeDiskSpaceLimit() const ; void setFreeDiskSpaceLimit(uint32_t size_in_mb) ; + uint32_t defaultEncryptionPolicy(); bool FileCancel(const RsFileHash& hash); bool FileControl(const RsFileHash& hash, uint32_t flags); diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index f68b7813b..97bbf1b04 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -294,6 +294,14 @@ void ftServer::setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy s) { mFtController->setDefaultChunkStrategy(s) ; } +uint32_t ftServer::defaultEncryptionPolicy() +{ + return mFtController->defaultEncryptionPolicy() ; +} +void ftServer::setDefaultEncryptionPolicy(uint32_t s) +{ + mFtController->setDefaultEncryptionPolicy(s) ; +} FileChunksInfo::ChunkStrategy ftServer::defaultChunkStrategy() { return mFtController->defaultChunkStrategy() ; diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index ef752dc85..f585c67f9 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -135,7 +135,8 @@ public: virtual FileChunksInfo::ChunkStrategy defaultChunkStrategy() ; virtual uint32_t freeDiskSpaceLimit() const ; virtual void setFreeDiskSpaceLimit(uint32_t size_in_mb) ; - + virtual void setDefaultEncryptionPolicy(uint32_t policy) ; // RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT/PERMISSIVE + virtual uint32_t defaultEncryptionPolicy() ; /*** * Control of Downloads Priority. diff --git a/libretroshare/src/ft/ftturtlefiletransferitem.cc b/libretroshare/src/ft/ftturtlefiletransferitem.cc index 4ec1123cc..b4ce91623 100644 --- a/libretroshare/src/ft/ftturtlefiletransferitem.cc +++ b/libretroshare/src/ft/ftturtlefiletransferitem.cc @@ -30,7 +30,7 @@ #include #include -uint32_t RsTurtleFileRequestItem::serial_size() +uint32_t RsTurtleFileRequestItem::serial_size() const { uint32_t s = 0 ; @@ -42,7 +42,7 @@ uint32_t RsTurtleFileRequestItem::serial_size() return s ; } -uint32_t RsTurtleFileDataItem::serial_size() +uint32_t RsTurtleFileDataItem::serial_size() const { uint32_t s = 0 ; @@ -55,7 +55,7 @@ uint32_t RsTurtleFileDataItem::serial_size() return s ; } -uint32_t RsTurtleFileMapRequestItem::serial_size() +uint32_t RsTurtleFileMapRequestItem::serial_size() const { uint32_t s = 0 ; @@ -66,7 +66,7 @@ uint32_t RsTurtleFileMapRequestItem::serial_size() return s ; } -uint32_t RsTurtleFileMapItem::serial_size() +uint32_t RsTurtleFileMapItem::serial_size() const { uint32_t s = 0 ; @@ -80,7 +80,7 @@ uint32_t RsTurtleFileMapItem::serial_size() return s ; } -uint32_t RsTurtleChunkCrcItem::serial_size() +uint32_t RsTurtleChunkCrcItem::serial_size() const { uint32_t s = 0 ; @@ -91,7 +91,7 @@ uint32_t RsTurtleChunkCrcItem::serial_size() return s ; } -uint32_t RsTurtleChunkCrcRequestItem::serial_size() +uint32_t RsTurtleChunkCrcRequestItem::serial_size() const { uint32_t s = 0 ; @@ -101,7 +101,7 @@ uint32_t RsTurtleChunkCrcRequestItem::serial_size() return s ; } -bool RsTurtleFileMapRequestItem::serialize(void *data,uint32_t& pktsize) +bool RsTurtleFileMapRequestItem::serialize(void *data,uint32_t& pktsize) const { uint32_t tlvsize = serial_size(); uint32_t offset = 0; @@ -134,7 +134,7 @@ bool RsTurtleFileMapRequestItem::serialize(void *data,uint32_t& pktsize) return ok; } -bool RsTurtleFileMapItem::serialize(void *data,uint32_t& pktsize) +bool RsTurtleFileMapItem::serialize(void *data,uint32_t& pktsize) const { uint32_t tlvsize = serial_size(); uint32_t offset = 0; @@ -171,7 +171,7 @@ bool RsTurtleFileMapItem::serialize(void *data,uint32_t& pktsize) return ok; } -bool RsTurtleChunkCrcRequestItem::serialize(void *data,uint32_t& pktsize) +bool RsTurtleChunkCrcRequestItem::serialize(void *data,uint32_t& pktsize) const { #ifdef P3TURTLE_DEBUG std::cerr << "RsTurtleChunkCrcRequestItem::serialize(): serializing packet:" << std::endl ; @@ -206,7 +206,7 @@ bool RsTurtleChunkCrcRequestItem::serialize(void *data,uint32_t& pktsize) return ok; } -bool RsTurtleChunkCrcItem::serialize(void *data,uint32_t& pktsize) +bool RsTurtleChunkCrcItem::serialize(void *data,uint32_t& pktsize) const { #ifdef P3TURTLE_DEBUG std::cerr << "RsTurtleChunkCrcRequestItem::serialize(): serializing packet:" << std::endl ; @@ -345,7 +345,7 @@ RsTurtleChunkCrcRequestItem::RsTurtleChunkCrcRequestItem(void *data,uint32_t pkt throw std::runtime_error("Unknown error while deserializing.") ; #endif } -bool RsTurtleFileRequestItem::serialize(void *data,uint32_t& pktsize) +bool RsTurtleFileRequestItem::serialize(void *data,uint32_t& pktsize) const { uint32_t tlvsize = serial_size(); uint32_t offset = 0; @@ -459,7 +459,7 @@ RsTurtleFileDataItem::RsTurtleFileDataItem(void *data,uint32_t pktsize) #endif } -bool RsTurtleFileDataItem::serialize(void *data,uint32_t& pktsize) +bool RsTurtleFileDataItem::serialize(void *data,uint32_t& pktsize) const { uint32_t tlvsize = serial_size(); uint32_t offset = 0; diff --git a/libretroshare/src/ft/ftturtlefiletransferitem.h b/libretroshare/src/ft/ftturtlefiletransferitem.h index 7bf2e8e43..8a886918e 100644 --- a/libretroshare/src/ft/ftturtlefiletransferitem.h +++ b/libretroshare/src/ft/ftturtlefiletransferitem.h @@ -44,8 +44,8 @@ class RsTurtleFileRequestItem: public RsTurtleGenericTunnelItem virtual std::ostream& print(std::ostream& o, uint16_t) ; protected: - virtual bool serialize(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; + virtual bool serialize(void *data,uint32_t& size) const; + virtual uint32_t serial_size() const; }; class RsTurtleFileDataItem: public RsTurtleGenericTunnelItem @@ -64,8 +64,8 @@ class RsTurtleFileDataItem: public RsTurtleGenericTunnelItem virtual std::ostream& print(std::ostream& o, uint16_t) ; - virtual bool serialize(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; + virtual bool serialize(void *data,uint32_t& size) const; + virtual uint32_t serial_size() const; }; class RsTurtleFileMapRequestItem: public RsTurtleGenericTunnelItem @@ -78,8 +78,8 @@ class RsTurtleFileMapRequestItem: public RsTurtleGenericTunnelItem virtual std::ostream& print(std::ostream& o, uint16_t) ; - virtual bool serialize(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; + virtual bool serialize(void *data,uint32_t& size) const; + virtual uint32_t serial_size() const; }; class RsTurtleFileMapItem: public RsTurtleGenericTunnelItem @@ -96,8 +96,8 @@ class RsTurtleFileMapItem: public RsTurtleGenericTunnelItem virtual std::ostream& print(std::ostream& o, uint16_t) ; - virtual bool serialize(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; + virtual bool serialize(void *data,uint32_t& size) const; + virtual uint32_t serial_size() const; }; class RsTurtleChunkCrcRequestItem: public RsTurtleGenericTunnelItem @@ -113,8 +113,8 @@ class RsTurtleChunkCrcRequestItem: public RsTurtleGenericTunnelItem virtual std::ostream& print(std::ostream& o, uint16_t) ; - virtual bool serialize(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; + virtual bool serialize(void *data,uint32_t& size) const; + virtual uint32_t serial_size() const; }; class RsTurtleChunkCrcItem: public RsTurtleGenericTunnelItem @@ -130,6 +130,6 @@ class RsTurtleChunkCrcItem: public RsTurtleGenericTunnelItem Sha1CheckSum check_sum ; virtual std::ostream& print(std::ostream& o, uint16_t) ; - virtual bool serialize(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; + virtual bool serialize(void *data,uint32_t& size) const; + virtual uint32_t serial_size() const; }; diff --git a/libretroshare/src/turtle/rsturtleitem.cc b/libretroshare/src/turtle/rsturtleitem.cc index 8139c9ad3..4095eceb1 100644 --- a/libretroshare/src/turtle/rsturtleitem.cc +++ b/libretroshare/src/turtle/rsturtleitem.cc @@ -16,7 +16,7 @@ // ---------------------------------- Packet sizes -----------------------------------// // -uint32_t RsTurtleStringSearchRequestItem::serial_size() +uint32_t RsTurtleStringSearchRequestItem::serial_size() const { uint32_t s = 0 ; @@ -27,7 +27,7 @@ uint32_t RsTurtleStringSearchRequestItem::serial_size() return s ; } -uint32_t RsTurtleRegExpSearchRequestItem::serial_size() +uint32_t RsTurtleRegExpSearchRequestItem::serial_size() const { uint32_t s = 0 ; @@ -48,7 +48,7 @@ uint32_t RsTurtleRegExpSearchRequestItem::serial_size() return s ; } -uint32_t RsTurtleSearchResultItem::serial_size() +uint32_t RsTurtleSearchResultItem::serial_size()const { uint32_t s = 0 ; @@ -67,7 +67,7 @@ uint32_t RsTurtleSearchResultItem::serial_size() return s ; } -uint32_t RsTurtleOpenTunnelItem::serial_size() +uint32_t RsTurtleOpenTunnelItem::serial_size()const { uint32_t s = 0 ; @@ -80,7 +80,7 @@ uint32_t RsTurtleOpenTunnelItem::serial_size() return s ; } -uint32_t RsTurtleTunnelOkItem::serial_size() +uint32_t RsTurtleTunnelOkItem::serial_size() const { uint32_t s = 0 ; @@ -91,7 +91,7 @@ uint32_t RsTurtleTunnelOkItem::serial_size() return s ; } -uint32_t RsTurtleGenericDataItem::serial_size() +uint32_t RsTurtleGenericDataItem::serial_size() const { uint32_t s = 0 ; @@ -159,7 +159,7 @@ RsItem *RsTurtleSerialiser::deserialise(void *data, uint32_t *size) } -bool RsTurtleStringSearchRequestItem::serialize(void *data,uint32_t& pktsize) +bool RsTurtleStringSearchRequestItem::serialize(void *data,uint32_t& pktsize) const { uint32_t tlvsize = serial_size(); uint32_t offset = 0; @@ -193,7 +193,7 @@ bool RsTurtleStringSearchRequestItem::serialize(void *data,uint32_t& pktsize) return ok; } -bool RsTurtleRegExpSearchRequestItem::serialize(void *data,uint32_t& pktsize) +bool RsTurtleRegExpSearchRequestItem::serialize(void *data,uint32_t& pktsize) const { uint32_t tlvsize = serial_size(); uint32_t offset = 0; @@ -313,7 +313,7 @@ RsTurtleRegExpSearchRequestItem::RsTurtleRegExpSearchRequestItem(void *data,uint #endif } -bool RsTurtleSearchResultItem::serialize(void *data,uint32_t& pktsize) +bool RsTurtleSearchResultItem::serialize(void *data,uint32_t& pktsize) const { uint32_t tlvsize = serial_size(); uint32_t offset = 0; @@ -398,7 +398,7 @@ RsTurtleSearchResultItem::RsTurtleSearchResultItem(void *data,uint32_t pktsize) #endif } -bool RsTurtleOpenTunnelItem::serialize(void *data,uint32_t& pktsize) +bool RsTurtleOpenTunnelItem::serialize(void *data,uint32_t& pktsize) const { uint32_t tlvsize = serial_size(); uint32_t offset = 0; @@ -464,7 +464,7 @@ RsTurtleOpenTunnelItem::RsTurtleOpenTunnelItem(void *data,uint32_t pktsize) #endif } -bool RsTurtleTunnelOkItem::serialize(void *data,uint32_t& pktsize) +bool RsTurtleTunnelOkItem::serialize(void *data,uint32_t& pktsize) const { uint32_t tlvsize = serial_size(); uint32_t offset = 0; @@ -572,7 +572,7 @@ RsTurtleGenericDataItem::RsTurtleGenericDataItem(void *data,uint32_t pktsize) #endif } -bool RsTurtleGenericDataItem::serialize(void *data,uint32_t& pktsize) +bool RsTurtleGenericDataItem::serialize(void *data,uint32_t& pktsize) const { uint32_t tlvsize = serial_size(); uint32_t offset = 0; diff --git a/libretroshare/src/turtle/rsturtleitem.h b/libretroshare/src/turtle/rsturtleitem.h index db210b49c..6cb1ad595 100644 --- a/libretroshare/src/turtle/rsturtleitem.h +++ b/libretroshare/src/turtle/rsturtleitem.h @@ -35,9 +35,8 @@ class RsTurtleItem: public RsItem public: RsTurtleItem(uint8_t turtle_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_TURTLE,turtle_subtype) {} -#warning we need some consts here - virtual bool serialize(void *data,uint32_t& size) = 0 ; // Isn't it better that items can serialize themselves ? - virtual uint32_t serial_size() = 0 ; // deserialise is handled using a constructor + virtual bool serialize(void *data,uint32_t& size) const = 0 ; // Isn't it better that items can serialize themselves ? + virtual uint32_t serial_size() const = 0 ; // deserialise is handled using a constructor virtual void clear() {} }; @@ -64,8 +63,8 @@ class RsTurtleSearchResultItem: public RsTurtleItem virtual std::ostream& print(std::ostream& o, uint16_t) ; protected: - virtual bool serialize(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; + virtual bool serialize(void *data,uint32_t& size) const ; + virtual uint32_t serial_size() const ; }; class RsTurtleSearchRequestItem: public RsTurtleItem @@ -93,8 +92,8 @@ class RsTurtleStringSearchRequestItem: public RsTurtleSearchRequestItem virtual std::ostream& print(std::ostream& o, uint16_t) ; protected: - virtual bool serialize(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; + virtual bool serialize(void *data,uint32_t& size) const ; + virtual uint32_t serial_size() const ; }; class RsTurtleRegExpSearchRequestItem: public RsTurtleSearchRequestItem @@ -110,8 +109,8 @@ class RsTurtleRegExpSearchRequestItem: public RsTurtleSearchRequestItem virtual std::ostream& print(std::ostream& o, uint16_t) ; protected: - virtual bool serialize(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; + virtual bool serialize(void *data,uint32_t& size) const ; + virtual uint32_t serial_size() const ; }; /***********************************************************************************/ @@ -132,8 +131,8 @@ class RsTurtleOpenTunnelItem: public RsTurtleItem virtual std::ostream& print(std::ostream& o, uint16_t) ; protected: - virtual bool serialize(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; + virtual bool serialize(void *data,uint32_t& size) const ; + virtual uint32_t serial_size() const ; }; class RsTurtleTunnelOkItem: public RsTurtleItem @@ -148,8 +147,8 @@ class RsTurtleTunnelOkItem: public RsTurtleItem virtual std::ostream& print(std::ostream& o, uint16_t) ; protected: - virtual bool serialize(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; + virtual bool serialize(void *data,uint32_t& size) const ; + virtual uint32_t serial_size() const ; }; /***********************************************************************************/ @@ -209,8 +208,8 @@ class RsTurtleGenericDataItem: public RsTurtleGenericTunnelItem virtual std::ostream& print(std::ostream& o, uint16_t) ; protected: - virtual bool serialize(void *data,uint32_t& size) ; - virtual uint32_t serial_size() ; + virtual bool serialize(void *data,uint32_t& size) const ; + virtual uint32_t serial_size() const ; }; /***********************************************************************************/ From 9a881619e13471f263bdb91ecf1379f918a04474 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Sat, 29 Oct 2016 18:35:48 +0200 Subject: [PATCH 14/52] added record for H(H(F)) in LocalDirectoryStorage --- libretroshare/src/file_sharing/directory_storage.cc | 12 ++++++++++++ libretroshare/src/file_sharing/directory_storage.h | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/libretroshare/src/file_sharing/directory_storage.cc b/libretroshare/src/file_sharing/directory_storage.cc index 80944f46a..e4633ff72 100644 --- a/libretroshare/src/file_sharing/directory_storage.cc +++ b/libretroshare/src/file_sharing/directory_storage.cc @@ -289,6 +289,10 @@ bool DirectoryStorage::getIndexFromDirHash(const RsFileHash& hash,EntryIndex& in /* Local Directory Storage */ /******************************************************************************************************************/ +RsFileHash LocalDirectoryStorage::makeEncryptedHash(const RsFileHash& hash) +{ + return RsDirUtil::sha1sum(hash.toByteArray(),hash.SIZE_IN_BYTES); +} bool LocalDirectoryStorage::locked_findRealHash(const RsFileHash& hash, RsFileHash& real_hash) const { std::map::const_iterator it = mEncryptedHashes.find(hash) ; @@ -454,7 +458,15 @@ void LocalDirectoryStorage::updateTimeStamps() #endif } } +bool LocalDirectoryStorage::updateHash(const EntryIndex& index,const RsFileHash& hash) +{ + { + RS_STACK_MUTEX(mDirStorageMtx) ; + mEncryptedHashes[makeEncryptedHash(hash)] = hash ; + } + return mFileHierarchy->updateHash(index,hash); +} std::string LocalDirectoryStorage::locked_findRealRootFromVirtualFilename(const std::string& virtual_rootdir) const { /**** MUST ALREADY BE LOCKED ****/ diff --git a/libretroshare/src/file_sharing/directory_storage.h b/libretroshare/src/file_sharing/directory_storage.h index b9c4a3ea0..09a46c2d7 100644 --- a/libretroshare/src/file_sharing/directory_storage.h +++ b/libretroshare/src/file_sharing/directory_storage.h @@ -139,7 +139,9 @@ class DirectoryStorage // Updates relevant information for the file at the given index. bool updateFile(const EntryIndex& index,const RsFileHash& hash, const std::string& fname, uint64_t size, time_t modf_time) ; - bool updateHash(const EntryIndex& index,const RsFileHash& hash); + + // This is derived in LocalDirectoryStorage in order to also store H(H(F)) + virtual bool updateHash(const EntryIndex& index,const RsFileHash& hash); // Returns the hash of the directory at the given index and reverse. This hash is set as random the first time it is used (when updating directories). It will be // used by the sync system to designate the directory without referring to index (index could be used to figure out the existance of hidden directories) @@ -215,6 +217,7 @@ public: void updateShareFlags(const SharedDirInfo& info) ; bool convertSharedFilePath(const std::string& path_with_virtual_name,std::string& fullpath) ; + virtual bool updateHash(const EntryIndex& index,const RsFileHash& hash); /*! * \brief searchHash * Looks into local database of shared files for the given hash. Also looks for files such that the hash of the hash @@ -273,6 +276,7 @@ public: bool serialiseDirEntry(const EntryIndex& indx, RsTlvBinaryData& bindata, const RsPeerId &client_id) ; private: + static RsFileHash makeEncryptedHash(const RsFileHash& hash); bool locked_findRealHash(const RsFileHash& hash, RsFileHash& real_hash) const; std::string locked_getVirtualPath(EntryIndex indx) const ; std::string locked_getVirtualDirName(EntryIndex indx) const ; From 34dcb410b408655d80b2733a20291aa563302156 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Sun, 30 Oct 2016 11:36:00 +0100 Subject: [PATCH 15/52] fixed a few bugs in ftServer for encrypted tunnel management --- libretroshare/src/file_sharing/p3filelists.cc | 6 +- libretroshare/src/ft/ftcontroller.cc | 6 +- libretroshare/src/ft/ftserver.cc | 102 +++++++++++++++--- libretroshare/src/ft/ftserver.h | 2 + .../src/gui/settings/TransferPage.ui | 3 + 5 files changed, 98 insertions(+), 21 deletions(-) diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index 199641298..bad026bbf 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -628,6 +628,7 @@ bool p3FileDatabase::findChildPointer(void *ref, int row, void *& result, FileSe result = NULL ; if (ref == NULL) + { if(flags & RS_FILE_HINTS_LOCAL) { if(row != 0) @@ -642,8 +643,9 @@ bool p3FileDatabase::findChildPointer(void *ref, int row, void *& result, FileSe convertEntryIndexToPointer(mRemoteDirectories[row]->root(),row+1,result); return true; } - else - return false; + else + return false; + } uint32_t fi; DirectoryStorage::EntryIndex e ; diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index 91e0c0dd9..6e0bbccbd 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -1825,7 +1825,7 @@ const std::string download_dir_ss("DOWN_DIR"); const std::string partial_dir_ss("PART_DIR"); const std::string default_chunk_strategy_ss("DEFAULT_CHUNK_STRATEGY"); const std::string free_space_limit_ss("FREE_SPACE_LIMIT"); -const std::string default_encryption_policy("DEFAULT_ENCRYPTION_POLICY"); +const std::string default_encryption_policy_ss("DEFAULT_ENCRYPTION_POLICY"); /* p3Config Interface */ @@ -1873,6 +1873,8 @@ bool ftController::saveList(bool &cleanup, std::list& saveData) break ; } + configMap[default_encryption_policy_ss] = (mDefaultEncryptionPolicy==RS_FILE_CTRL_ENCRYPTION_POLICY_PERMISSIVE)?"PERMISSIVE":"STRICT" ; + rs_sprintf(s, "%lu", RsDiscSpace::freeSpaceLimit()); configMap[free_space_limit_ss] = s ; @@ -2115,7 +2117,7 @@ bool ftController::loadConfigMap(std::map &configMap) setPartialsDirectory(mit->second); } - if (configMap.end() != (mit = configMap.find(default_encryption_policy))) + if (configMap.end() != (mit = configMap.find(default_encryption_policy_ss))) { if(mit->second == "STRICT") { diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 97bbf1b04..517f5e387 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -57,6 +57,11 @@ const int ftserverzone = 29539; * #define SERVER_DEBUG_CACHE 1 ***/ +#define SERVER_DEBUG 1 + +#define FTSERVER_DEBUG() std::cerr << time(NULL) << " : FILE_SERVER : " << __FUNCTION__ << " : " +#define FTSERVER_ERROR() std::cerr << "(EE) FILE_SERVER ERROR : " + static const time_t FILE_TRANSFER_LOW_PRIORITY_TASKS_PERIOD = 5 ; // low priority tasks handling every 5 seconds /* Setup */ @@ -259,8 +264,18 @@ bool ftServer::activateTunnels(const RsFileHash& hash,TransferRequestFlags flags if(onoff) { - if(flags & RS_FILE_REQ_ENCRYPTED) mTurtleRouter->monitorTunnels(hash_of_hash,this,true) ; - if(flags & RS_FILE_REQ_UNENCRYPTED) mTurtleRouter->monitorTunnels(hash,this,true) ; + std::cerr << "Activating tunnels for hash " << hash << std::endl; + + if(flags & RS_FILE_REQ_ENCRYPTED) + { + std::cerr << " flags require end-to-end encryption. Requesting hash of hash " << hash_of_hash << std::endl; + mTurtleRouter->monitorTunnels(hash_of_hash,this,true) ; + } + if(flags & RS_FILE_REQ_UNENCRYPTED) + { + std::cerr << " flags require no end-to-end encryption. Requesting hash " << hash << std::endl; + mTurtleRouter->monitorTunnels(hash,this,true) ; + } } else { @@ -477,12 +492,42 @@ RsTurtleGenericTunnelItem *ftServer::deserialiseItem(void *data,uint32_t size) c void ftServer::addVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction dir) { - if(dir == RsTurtleGenericTunnelItem::DIRECTION_SERVER) - mFtController->addFileSource(hash,virtual_peer_id) ; +#ifdef SERVER_DEBUG + FTSERVER_DEBUG() << "adding virtual peer. Direction=" << dir << ", hash=" << hash << ", vpid=" << virtual_peer_id << std::endl; +#endif + if(dir == RsTurtleGenericTunnelItem::DIRECTION_SERVER) + { + RsFileHash real_hash ; + if(findRealHash(hash,real_hash)) + { +#ifdef SERVER_DEBUG + FTSERVER_DEBUG() << " direction is SERVER. Adding file source for end-to-end encrypted tunnel for real hash " << real_hash << ", virtual peer id = " << virtual_peer_id << std::endl; +#endif + { + RS_STACK_MUTEX(srvMutex) ; + mEncryptedPeerIds[virtual_peer_id] = hash ; + } + mFtController->addFileSource(real_hash,virtual_peer_id) ; + } + else + { +#ifdef SERVER_DEBUG + FTSERVER_DEBUG() << " direction is SERVER. Adding file source for unencrypted tunnel" << std::endl; +#endif + mFtController->addFileSource(hash,virtual_peer_id) ; + } + } } void ftServer::removeVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id) { - mFtController->removeFileSource(hash,virtual_peer_id) ; + RsFileHash real_hash ; + if(findRealHash(hash,real_hash)) + mFtController->removeFileSource(real_hash,virtual_peer_id) ; + else + mFtController->removeFileSource(hash,virtual_peer_id) ; + + RS_STACK_MUTEX(srvMutex) ; + mEncryptedPeerIds.erase(virtual_peer_id) ; } bool ftServer::handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_id) @@ -520,7 +565,7 @@ bool ftServer::handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_i std::cerr << " peer = " << peer_id << std::endl; std::cerr << " flags = " << info.storage_permission_flags << std::endl; std::cerr << " local = " << rsFiles->FileDetails(hash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY | RS_FILE_HINTS_DOWNLOAD, info) << std::endl; - std::cerr << " groups= " ; for(std::list::const_iterator it(info.parent_groups.begin());it!=info.parent_groups.end();++it) std::cerr << (*it) << ", " ; std::cerr << std::endl; + std::cerr << " groups= " ; for(std::list::const_iterator it(info.parent_groups.begin());it!=info.parent_groups.end();++it) std::cerr << (*it) << ", " ; std::cerr << std::endl; std::cerr << " clear = " << rsPeers->computePeerPermissionFlags(peer_id,info.storage_permission_flags,info.parent_groups) << std::endl; } #endif @@ -766,17 +811,19 @@ bool ftServer::shareDownloadDirectory(bool share) bool ftServer::sendTurtleItem(const RsPeerId& peerId,const RsFileHash& hash,RsTurtleGenericTunnelItem *item) { - // first, we look for the encrypted hash map -#warning code needed here - if(true) - { - // we don't encrypt - mTurtleRouter->sendTurtleData(peerId,item) ; - } - else + // we cannot look in the encrypted hash map, since the same hash--on this side of the FT--can be used with both + // encrypted and unencrypted peers ids. So the information comes from the virtual peer Id. + + RsFileHash encrypted_hash; + + if(findEncryptedHash(peerId,encrypted_hash)) { // we encrypt the item +#ifdef SERVER_DEBUG + FTSERVER_DEBUG() << "Sending turtle item to peer ID " << peerId << " using encrypted tunnel." << std::endl; +#endif + RsTurtleGenericDataItem *encrypted_item ; if(!encryptItem(item, hash, encrypted_item)) @@ -786,6 +833,14 @@ bool ftServer::sendTurtleItem(const RsPeerId& peerId,const RsFileHash& hash,RsTu mTurtleRouter->sendTurtleData(peerId,encrypted_item) ; } + else + { +#ifdef SERVER_DEBUG + FTSERVER_DEBUG() << "Sending turtle item to peer ID " << peerId << " using non uncrypted tunnel." << std::endl; +#endif + mTurtleRouter->sendTurtleData(peerId,item) ; + } + return true ; } @@ -1230,8 +1285,24 @@ bool ftServer::encryptHash(const RsFileHash& hash, RsFileHash& hash_of_hash) return true ; } +bool ftServer::findEncryptedHash(const RsPeerId& virtual_peer_id, RsFileHash& encrypted_hash) +{ + RS_STACK_MUTEX(srvMutex); + + std::map::const_iterator it = mEncryptedPeerIds.find(virtual_peer_id) ; + + if(it != mEncryptedPeerIds.end()) + { + encrypted_hash = it->second ; + return true ; + } + else + return false ; +} + bool ftServer::findRealHash(const RsFileHash& hash, RsFileHash& real_hash) { + RS_STACK_MUTEX(srvMutex); std::map::const_iterator it = mEncryptedHashes.find(hash) ; if(it != mEncryptedHashes.end()) @@ -1391,9 +1462,6 @@ int ftServer::handleIncoming() int nhandled = 0 ; RsItem *item = NULL ; -#ifdef SERVER_DEBUG - std::cerr << "ftServer::handleIncoming() " << std::endl; -#endif while(NULL != (item = recvItem())) { diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index f585c67f9..5d17da77e 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -258,6 +258,7 @@ protected: // fnds out what is the real hash of encrypted hash hash bool findRealHash(const RsFileHash& hash, RsFileHash& real_hash); + bool findEncryptedHash(const RsPeerId& virtual_peer_id, RsFileHash& encrypted_hash); bool encryptHash(const RsFileHash& hash, RsFileHash& hash_of_hash); private: @@ -286,6 +287,7 @@ private: std::string mPartialsPath; std::map mEncryptedHashes ; // This map is such that sha1(it->second) = it->first + std::map mEncryptedPeerIds ; // This map holds the hash to be used with each peer id }; diff --git a/retroshare-gui/src/gui/settings/TransferPage.ui b/retroshare-gui/src/gui/settings/TransferPage.ui index 88f8a3730..665009d65 100644 --- a/retroshare-gui/src/gui/settings/TransferPage.ui +++ b/retroshare-gui/src/gui/settings/TransferPage.ui @@ -144,6 +144,9 @@ + + <html><head/><body><p>Anonymous tunnels can be end-o-end encrypted. In order to maintain backward compatibility, this can be made optional (choosing &quot;Accepted&quot;), but in the end, all Retroshare nodes will be switched to &quot;Enforced&quot;, meaning that all anonymous transfers will be end-to-end encrypted.</p></body></html> + Accepted From def20a3f4ccc4db1d1b3bc677e2535345a877ff3 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Sun, 30 Oct 2016 15:11:22 +0100 Subject: [PATCH 16/52] encrypted FT works. Fixed last bugs in ftServer --- libretroshare/src/crypto/chacha20.cpp | 25 +++++++++++++--- libretroshare/src/crypto/chacha20.h | 5 +++- libretroshare/src/ft/ftserver.cc | 41 +++++++++++++++------------ 3 files changed, 48 insertions(+), 23 deletions(-) diff --git a/libretroshare/src/crypto/chacha20.cpp b/libretroshare/src/crypto/chacha20.cpp index 58b06d660..4561d281f 100644 --- a/libretroshare/src/crypto/chacha20.cpp +++ b/libretroshare/src/crypto/chacha20.cpp @@ -24,6 +24,7 @@ */ #include #include +#include #include #include #include @@ -524,7 +525,7 @@ bool AEAD_chacha20_poly1305(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uin } } -bool AEAD_chacha20_sha256(uint8_t key[32], uint8_t nonce[12], uint8_t *data, uint32_t data_size, uint8_t tag[16], bool encrypt) +bool AEAD_chacha20_sha256(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint32_t data_size,uint8_t *aad,uint32_t aad_size,uint8_t tag[16],bool encrypt) { // encrypt + tag. See RFC7539-2.8 @@ -534,7 +535,16 @@ bool AEAD_chacha20_sha256(uint8_t key[32], uint8_t nonce[12], uint8_t *data, uin uint8_t computed_tag[EVP_MAX_MD_SIZE]; unsigned int md_size ; - HMAC(EVP_sha256(),key,32,data,data_size,computed_tag,&md_size) ; + + HMAC_CTX hmac_ctx ; + HMAC_CTX_init(&hmac_ctx) ; + + HMAC_Init(&hmac_ctx,key,32,EVP_sha256()) ; + HMAC_Update(&hmac_ctx,aad,aad_size) ; + HMAC_Update(&hmac_ctx,data,data_size) ; + HMAC_Final(&hmac_ctx,computed_tag,&md_size) ; + + assert(md_size >= 16); memcpy(tag,computed_tag,16) ; @@ -544,7 +554,14 @@ bool AEAD_chacha20_sha256(uint8_t key[32], uint8_t nonce[12], uint8_t *data, uin { uint8_t computed_tag[EVP_MAX_MD_SIZE]; unsigned int md_size ; - HMAC(EVP_sha256(),key,32,data,data_size,computed_tag,&md_size) ; + + HMAC_CTX hmac_ctx ; + HMAC_CTX_init(&hmac_ctx) ; + + HMAC_Init(&hmac_ctx,key,32,EVP_sha256()) ; + HMAC_Update(&hmac_ctx,aad,aad_size) ; + HMAC_Update(&hmac_ctx,data,data_size) ; + HMAC_Final(&hmac_ctx,computed_tag,&md_size) ; // decrypt @@ -1207,7 +1224,7 @@ bool perform_tests() } { RsScopeTimer s("AEAD3") ; - AEAD_chacha20_sha256(key,nonce,ten_megabyte_data,SIZE,received_tag,true) ; + AEAD_chacha20_sha256(key,nonce,ten_megabyte_data,SIZE,aad,12,received_tag,true) ; std::cerr << " AEAD/sha256 encryption speed : " << SIZE / (1024.0*1024.0) / s.duration() << " MB/s" << std::endl; } diff --git a/libretroshare/src/crypto/chacha20.h b/libretroshare/src/crypto/chacha20.h index 1e289d0b9..ffce04605 100644 --- a/libretroshare/src/crypto/chacha20.h +++ b/libretroshare/src/crypto/chacha20.h @@ -81,13 +81,16 @@ namespace librs * \param nonce nonce. *Should be unique* in order to make chacha20 stream cipher unique. * \param data data that is encrypted/decrypted in place * \param data_size size of data to encrypt/authenticate + * \param aad additional authenticated data. Can be used to authenticate the nonce. + * \param aad_size * \param tag 16 bytes authentication tag result * \param encrypt true to encrypt, false to decrypt and check the tag. * \return * always true for encryption. * authentication result for decryption. data is *always* xored to the cipher stream whatever the authentication result is. */ - bool AEAD_chacha20_sha256(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint32_t data_size,uint8_t tag[16],bool encrypt); + bool AEAD_chacha20_sha256(uint8_t key[32], uint8_t nonce[12],uint8_t *data,uint32_t data_size,uint8_t *aad,uint32_t aad_size,uint8_t tag[16],bool encrypt_or_decrypt) ; + /*! * \brief constant_time_memcmp * Provides a constant time comparison of two memory chunks. Calls CRYPTO_memcmp. diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 517f5e387..b72ae350b 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -495,29 +495,27 @@ void ftServer::addVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeer #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "adding virtual peer. Direction=" << dir << ", hash=" << hash << ", vpid=" << virtual_peer_id << std::endl; #endif - if(dir == RsTurtleGenericTunnelItem::DIRECTION_SERVER) + RsFileHash real_hash ; + { - RsFileHash real_hash ; if(findRealHash(hash,real_hash)) { -#ifdef SERVER_DEBUG - FTSERVER_DEBUG() << " direction is SERVER. Adding file source for end-to-end encrypted tunnel for real hash " << real_hash << ", virtual peer id = " << virtual_peer_id << std::endl; -#endif - { - RS_STACK_MUTEX(srvMutex) ; - mEncryptedPeerIds[virtual_peer_id] = hash ; - } - mFtController->addFileSource(real_hash,virtual_peer_id) ; + RS_STACK_MUTEX(srvMutex) ; + mEncryptedPeerIds[virtual_peer_id] = hash ; } else - { + real_hash = hash; + } + + if(dir == RsTurtleGenericTunnelItem::DIRECTION_SERVER) + { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << " direction is SERVER. Adding file source for unencrypted tunnel" << std::endl; + FTSERVER_DEBUG() << " direction is SERVER. Adding file source for end-to-end encrypted tunnel for real hash " << real_hash << ", virtual peer id = " << virtual_peer_id << std::endl; #endif - mFtController->addFileSource(hash,virtual_peer_id) ; - } + mFtController->addFileSource(real_hash,virtual_peer_id) ; } } + void ftServer::removeVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id) { RsFileHash real_hash ; @@ -538,7 +536,8 @@ bool ftServer::handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_i if(info.transfer_info_flags & RS_FILE_REQ_ENCRYPTED) { std::cerr << "handleTunnelRequest: openning encrypted FT tunnel for H(H(F))=" << hash << " and H(F)=" << info.hash << std::endl; - mEncryptedHashes[info.hash] = hash ; + RS_STACK_MUTEX(srvMutex) ; + mEncryptedHashes[hash] = info.hash; } #warning needs to tweak for swarming with encrypted FT if( (!res) && FileDetails(hash,RS_FILE_HINTS_DOWNLOAD,info)) @@ -1147,7 +1146,7 @@ bool ftServer::encryptItem(RsTurtleGenericTunnelItem *clear_item,const RsFileHas std::cerr << "ftServer::Encrypting ft item." << std::endl; std::cerr << " random nonce : " << RsUtil::BinToHex(initialization_vector,ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE) << std::endl; - uint32_t total_data_size = ENCRYPTED_FT_HEADER_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + clear_item->serial_size() + ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE ; + uint32_t total_data_size = ENCRYPTED_FT_HEADER_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_EDATA_SIZE + clear_item->serial_size() + ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE ; std::cerr << " clear part size : " << clear_item->serial_size() << std::endl; std::cerr << " total item size : " << total_data_size << std::endl; @@ -1199,7 +1198,7 @@ bool ftServer::encryptItem(RsTurtleGenericTunnelItem *clear_item,const RsFileHas if(edata[2] == ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_POLY1305) librs::crypto::AEAD_chacha20_poly1305(encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset],true) ; else if(edata[2] == ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_SHA256) - librs::crypto::AEAD_chacha20_sha256(encryption_key,initialization_vector,&edata[aad_offset],edata_size+ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE+ENCRYPTED_FT_EDATA_SIZE, &edata[authentication_tag_offset],true) ; + librs::crypto::AEAD_chacha20_sha256 (encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset],true) ; else return false ; @@ -1247,6 +1246,12 @@ bool ftServer::decryptItem(RsTurtleGenericDataItem *encrypted_item,const RsFileH edata_size += ((uint32_t)edata[offset+2]) << 16 ; edata_size += ((uint32_t)edata[offset+3]) << 24 ; + if(edata_size + ENCRYPTED_FT_EDATA_SIZE + ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_HEADER_SIZE != encrypted_item->data_size) + { + std::cerr << " ERROR: encrypted data size is " << edata_size << ", should be " << encrypted_item->data_size - (ENCRYPTED_FT_EDATA_SIZE + ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_HEADER_SIZE ) << std::endl; + return false ; + } + offset += ENCRYPTED_FT_EDATA_SIZE ; uint32_t clear_item_offset = offset ; @@ -1258,7 +1263,7 @@ bool ftServer::decryptItem(RsTurtleGenericDataItem *encrypted_item,const RsFileH if(edata[2] == ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_POLY1305) result = librs::crypto::AEAD_chacha20_poly1305(encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset],false) ; else if(edata[2] == ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_SHA256) - result = librs::crypto::AEAD_chacha20_sha256(encryption_key,initialization_vector,&edata[aad_offset],edata_size+ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE+ENCRYPTED_FT_EDATA_SIZE, &edata[authentication_tag_offset],false) ; + result = librs::crypto::AEAD_chacha20_sha256 (encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset],false) ; else return false ; From 5b9ef0435832ad354f9d3a1a75743521a5d291a4 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Sun, 30 Oct 2016 15:33:05 +0100 Subject: [PATCH 17/52] improved debug output in ftserver --- libretroshare/src/ft/ftserver.cc | 178 ++++++++++-------- libretroshare/src/ft/ftserver.h | 1 + libretroshare/src/retroshare/rsfiles.h | 1 + .../src/gui/FileTransfer/TransfersDialog.cpp | 5 + 4 files changed, 106 insertions(+), 79 deletions(-) diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index b72ae350b..3b0b8d3f8 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -247,7 +247,9 @@ bool ftServer::alreadyHaveFile(const RsFileHash& hash, FileInfo &info) bool ftServer::FileRequest(const std::string& fname, const RsFileHash& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list& srcIds) { - std::cerr << "Requesting " << fname << std::endl ; +#ifdef SERVER_DEBUG + FTSERVER_DEBUG() << "Requesting " << fname << std::endl ; +#endif if(!mFtController->FileRequest(fname, hash, size, dest, flags, srcIds)) return false ; @@ -264,16 +266,22 @@ bool ftServer::activateTunnels(const RsFileHash& hash,TransferRequestFlags flags if(onoff) { - std::cerr << "Activating tunnels for hash " << hash << std::endl; +#ifdef SERVER_DEBUG + FTSERVER_DEBUG() << "Activating tunnels for hash " << hash << std::endl; +#endif if(flags & RS_FILE_REQ_ENCRYPTED) { - std::cerr << " flags require end-to-end encryption. Requesting hash of hash " << hash_of_hash << std::endl; +#ifdef SERVER_DEBUG + FTSERVER_DEBUG() << " flags require end-to-end encryption. Requesting hash of hash " << hash_of_hash << std::endl; +#endif mTurtleRouter->monitorTunnels(hash_of_hash,this,true) ; } if(flags & RS_FILE_REQ_UNENCRYPTED) { - std::cerr << " flags require no end-to-end encryption. Requesting hash " << hash << std::endl; +#ifdef SERVER_DEBUG + FTSERVER_DEBUG() << " flags require no end-to-end encryption. Requesting hash " << hash << std::endl; +#endif mTurtleRouter->monitorTunnels(hash,this,true) ; } } @@ -459,11 +467,11 @@ RsTurtleGenericTunnelItem *ftServer::deserialiseItem(void *data,uint32_t size) c uint32_t rstype = getRsItemId(data); #ifdef SERVER_DEBUG - std::cerr << "p3turtle: deserialising packet: " << std::endl ; + FTSERVER_DEBUG() << "p3turtle: deserialising packet: " << std::endl ; #endif if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_TURTLE != getRsItemService(rstype))) { - std::cerr << " Wrong type !!" << std::endl ; + FTSERVER_ERROR() << " Wrong type !!" << std::endl ; return NULL; /* wrong type */ } @@ -484,13 +492,20 @@ RsTurtleGenericTunnelItem *ftServer::deserialiseItem(void *data,uint32_t size) c } catch(std::exception& e) { - std::cerr << "(EE) deserialisation error in " << __PRETTY_FUNCTION__ << ": " << e.what() << std::endl; + FTSERVER_ERROR() << "(EE) deserialisation error in " << __PRETTY_FUNCTION__ << ": " << e.what() << std::endl; return NULL ; } } -void ftServer::addVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction dir) +bool ftServer::isEncryptedSource(const RsPeerId& virtual_peer_id) +{ + RS_STACK_MUTEX(srvMutex) ; + + return mEncryptedPeerIds.find(virtual_peer_id) != mEncryptedPeerIds.end(); +} + +void ftServer::addVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction dir) { #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "adding virtual peer. Direction=" << dir << ", hash=" << hash << ", vpid=" << virtual_peer_id << std::endl; @@ -535,7 +550,10 @@ bool ftServer::handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_i if(info.transfer_info_flags & RS_FILE_REQ_ENCRYPTED) { - std::cerr << "handleTunnelRequest: openning encrypted FT tunnel for H(H(F))=" << hash << " and H(F)=" << info.hash << std::endl; +#ifdef SERVER_DEBUG + FTSERVER_DEBUG() << "handleTunnelRequest: openning encrypted FT tunnel for H(H(F))=" << hash << " and H(F)=" << info.hash << std::endl; +#endif + RS_STACK_MUTEX(srvMutex) ; mEncryptedHashes[hash] = info.hash; } @@ -555,17 +573,20 @@ bool ftServer::handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_i } } #ifdef SERVER_DEBUG - std::cerr << "ftServer: performing local hash search for hash " << hash << std::endl; + FTSERVER_DEBUG() << "ftServer: performing local hash search for hash " << hash << std::endl; if(res) { - std::cerr << "Found hash: " << std::endl; - std::cerr << " hash = " << hash << std::endl; - std::cerr << " peer = " << peer_id << std::endl; - std::cerr << " flags = " << info.storage_permission_flags << std::endl; - std::cerr << " local = " << rsFiles->FileDetails(hash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY | RS_FILE_HINTS_DOWNLOAD, info) << std::endl; - std::cerr << " groups= " ; for(std::list::const_iterator it(info.parent_groups.begin());it!=info.parent_groups.end();++it) std::cerr << (*it) << ", " ; std::cerr << std::endl; - std::cerr << " clear = " << rsPeers->computePeerPermissionFlags(peer_id,info.storage_permission_flags,info.parent_groups) << std::endl; + FTSERVER_DEBUG() << "Found hash: " << std::endl; + FTSERVER_DEBUG() << " hash = " << hash << std::endl; + FTSERVER_DEBUG() << " peer = " << peer_id << std::endl; + FTSERVER_DEBUG() << " flags = " << info.storage_permission_flags << std::endl; + FTSERVER_DEBUG() << " local = " << rsFiles->FileDetails(hash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY | RS_FILE_HINTS_DOWNLOAD, info) << std::endl; + FTSERVER_DEBUG() << " groups= " ; + for(std::list::const_iterator it(info.parent_groups.begin());it!=info.parent_groups.end();++it) + FTSERVER_DEBUG() << (*it) << ", " ; + FTSERVER_DEBUG() << std::endl; + FTSERVER_DEBUG() << " clear = " << rsPeers->computePeerPermissionFlags(peer_id,info.storage_permission_flags,info.parent_groups) << std::endl; } #endif @@ -720,34 +741,27 @@ bool ftServer::removeSharedDirectory(std::string dir) std::list::iterator it; #ifdef SERVER_DEBUG - std::cerr << "ftServer::removeSharedDirectory(" << dir << ")"; - std::cerr << std::endl; + FTSERVER_DEBUG() << "ftServer::removeSharedDirectory(" << dir << ")" << std::endl; #endif mFileDatabase->getSharedDirectories(dirList); #ifdef SERVER_DEBUG for(it = dirList.begin(); it != dirList.end(); ++it) - { - std::cerr << "ftServer::removeSharedDirectory()"; - std::cerr << " existing: " << (*it).filename; - std::cerr << std::endl; - } + FTSERVER_DEBUG() << " existing: " << (*it).filename << std::endl; #endif for(it = dirList.begin();it!=dirList.end() && (*it).filename != dir;++it) ; if(it == dirList.end()) { - std::cerr << "(EE) ftServer::removeSharedDirectory(): Cannot Find Directory... Fail" << std::endl; + FTSERVER_ERROR() << "(EE) ftServer::removeSharedDirectory(): Cannot Find Directory... Fail" << std::endl; return false; } #ifdef SERVER_DEBUG - std::cerr << "ftServer::removeSharedDirectory()"; - std::cerr << " Updating Directories"; - std::cerr << std::endl; + FTSERVER_DEBUG() << " Updating Directories" << std::endl; #endif dirList.erase(it); @@ -847,7 +861,7 @@ bool ftServer::sendTurtleItem(const RsPeerId& peerId,const RsFileHash& hash,RsTu bool ftServer::sendDataRequest(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize) { #ifdef SERVER_DEBUG - std::cerr << "ftServer::sendDataRequest() to peer " << peerId << " for hash " << hash << ", offset=" << offset << ", chunk size="<< chunksize << std::endl; + FTSERVER_DEBUG() << "ftServer::sendDataRequest() to peer " << peerId << " for hash " << hash << ", offset=" << offset << ", chunk size="<< chunksize << std::endl; #endif if(mTurtleRouter->isTurtlePeer(peerId)) { @@ -884,7 +898,7 @@ bool ftServer::sendDataRequest(const RsPeerId& peerId, const RsFileHash& hash, u bool ftServer::sendChunkMapRequest(const RsPeerId& peerId,const RsFileHash& hash,bool is_client) { #ifdef SERVER_DEBUG - std::cerr << "ftServer::sendChunkMapRequest() to peer " << peerId << " for hash " << hash << std::endl; + FTSERVER_DEBUG() << "ftServer::sendChunkMapRequest() to peer " << peerId << " for hash " << hash << std::endl; #endif if(mTurtleRouter->isTurtlePeer(peerId)) { @@ -913,7 +927,7 @@ bool ftServer::sendChunkMapRequest(const RsPeerId& peerId,const RsFileHash& hash bool ftServer::sendChunkMap(const RsPeerId& peerId,const RsFileHash& hash,const CompressedChunkMap& map,bool is_client) { #ifdef SERVER_DEBUG - std::cerr << "ftServer::sendChunkMap() to peer " << peerId << " for hash " << hash << std::endl; + FTSERVER_DEBUG() << "ftServer::sendChunkMap() to peer " << peerId << " for hash " << hash << std::endl; #endif if(mTurtleRouter->isTurtlePeer(peerId)) { @@ -944,7 +958,7 @@ bool ftServer::sendChunkMap(const RsPeerId& peerId,const RsFileHash& hash,const bool ftServer::sendSingleChunkCRCRequest(const RsPeerId& peerId,const RsFileHash& hash,uint32_t chunk_number) { #ifdef SERVER_DEBUG - std::cerr << "ftServer::sendSingleCRCRequest() to peer " << peerId << " for hash " << hash << ", chunk number=" << chunk_number << std::endl; + FTSERVER_DEBUG() << "ftServer::sendSingleCRCRequest() to peer " << peerId << " for hash " << hash << ", chunk number=" << chunk_number << std::endl; #endif if(mTurtleRouter->isTurtlePeer(peerId)) { @@ -975,7 +989,7 @@ bool ftServer::sendSingleChunkCRCRequest(const RsPeerId& peerId,const RsFileHash bool ftServer::sendSingleChunkCRC(const RsPeerId& peerId,const RsFileHash& hash,uint32_t chunk_number,const Sha1CheckSum& crc) { #ifdef SERVER_DEBUG - std::cerr << "ftServer::sendSingleCRC() to peer " << peerId << " for hash " << hash << ", chunk number=" << chunk_number << std::endl; + FTSERVER_DEBUG() << "ftServer::sendSingleCRC() to peer " << peerId << " for hash " << hash << ", chunk number=" << chunk_number << std::endl; #endif if(mTurtleRouter->isTurtlePeer(peerId)) { @@ -1015,12 +1029,7 @@ bool ftServer::sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t uint32_t chunk; #ifdef SERVER_DEBUG - std::cerr << "ftServer::sendData() to " << peerId << std::endl; - std::cerr << "hash: " << hash; - std::cerr << " offset: " << baseoffset; - std::cerr << " chunk: " << chunksize; - std::cerr << " data: " << data; - std::cerr << std::endl; + FTSERVER_DEBUG() << "ftServer::sendData() to " << peerId << ", hash: " << hash << " offset: " << baseoffset << " chunk: " << chunksize << " data: " << data << std::endl; #endif while(tosend > 0) @@ -1080,12 +1089,7 @@ bool ftServer::sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t /* print the data pointer */ #ifdef SERVER_DEBUG - std::cerr << "ftServer::sendData() Packet: " << std::endl; - std::cerr << " offset: " << rfd->fd.file_offset; - std::cerr << " chunk: " << chunk; - std::cerr << " len: " << rfd->fd.binData.bin_len; - std::cerr << " data: " << rfd->fd.binData.bin_data; - std::cerr << std::endl; + FTSERVER_DEBUG() << "ftServer::sendData() Packet: " << " offset: " << rfd->fd.file_offset << " chunk: " << chunk << " len: " << rfd->fd.binData.bin_len << " data: " << rfd->fd.binData.bin_data << std::endl; #endif } @@ -1143,13 +1147,17 @@ bool ftServer::encryptItem(RsTurtleGenericTunnelItem *clear_item,const RsFileHas RSRandom::random_bytes(initialization_vector,ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE) ; - std::cerr << "ftServer::Encrypting ft item." << std::endl; - std::cerr << " random nonce : " << RsUtil::BinToHex(initialization_vector,ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE) << std::endl; +#ifdef SERVER_DEBUG + FTSERVER_DEBUG() << "ftServer::Encrypting ft item." << std::endl; + FTSERVER_DEBUG() << " random nonce : " << RsUtil::BinToHex(initialization_vector,ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE) << std::endl; +#endif uint32_t total_data_size = ENCRYPTED_FT_HEADER_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_EDATA_SIZE + clear_item->serial_size() + ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE ; - std::cerr << " clear part size : " << clear_item->serial_size() << std::endl; - std::cerr << " total item size : " << total_data_size << std::endl; +#ifdef SERVER_DEBUG + FTSERVER_DEBUG() << " clear part size : " << clear_item->serial_size() << std::endl; + FTSERVER_DEBUG() << " total item size : " << total_data_size << std::endl; +#endif encrypted_item = new RsTurtleGenericDataItem ; encrypted_item->data_bytes = rs_malloc( total_data_size ) ; @@ -1184,7 +1192,9 @@ bool ftServer::encryptItem(RsTurtleGenericTunnelItem *clear_item,const RsFileHas uint32_t ser_size = (uint32_t)((int)total_data_size - (int)offset); clear_item->serialize(&edata[offset], ser_size); - std::cerr << " clear item : " << RsUtil::BinToHex(&edata[offset],std::min(50,(int)total_data_size-(int)offset)) << "(...)" << std::endl; +#ifdef SERVER_DEBUG + FTSERVER_DEBUG() << " clear item : " << RsUtil::BinToHex(&edata[offset],std::min(50,(int)total_data_size-(int)offset)) << "(...)" << std::endl; +#endif uint32_t clear_item_offset = offset ; offset += edata_size ; @@ -1202,9 +1212,11 @@ bool ftServer::encryptItem(RsTurtleGenericTunnelItem *clear_item,const RsFileHas else return false ; - std::cerr << " encryption key : " << RsUtil::BinToHex(encryption_key,32) << std::endl; - std::cerr << " authen. tag : " << RsUtil::BinToHex(&edata[authentication_tag_offset],ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE) << std::endl; - std::cerr << " final item : " << RsUtil::BinToHex(&edata[0],std::min(50u,total_data_size)) << "(...)" << std::endl; +#ifdef SERVER_DEBUG + FTSERVER_DEBUG() << " encryption key : " << RsUtil::BinToHex(encryption_key,32) << std::endl; + FTSERVER_DEBUG() << " authen. tag : " << RsUtil::BinToHex(&edata[authentication_tag_offset],ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE) << std::endl; + FTSERVER_DEBUG() << " final item : " << RsUtil::BinToHex(&edata[0],std::min(50u,total_data_size)) << "(...)" << std::endl; +#endif return true ; } @@ -1232,11 +1244,13 @@ bool ftServer::decryptItem(RsTurtleGenericDataItem *encrypted_item,const RsFileH uint8_t *initialization_vector = &edata[offset] ; - std::cerr << "ftServer::decrypting ft item." << std::endl; - std::cerr << " item data : " << RsUtil::BinToHex(edata,std::min(50u,encrypted_item->data_size)) << "(...)" << std::endl; - std::cerr << " hash : " << hash << std::endl; - std::cerr << " encryption key : " << RsUtil::BinToHex(encryption_key,32) << std::endl; - std::cerr << " random nonce : " << RsUtil::BinToHex(initialization_vector,ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE) << std::endl; +#ifdef SERVER_DEBUG + FTSERVER_DEBUG() << "ftServer::decrypting ft item." << std::endl; + FTSERVER_DEBUG() << " item data : " << RsUtil::BinToHex(edata,std::min(50u,encrypted_item->data_size)) << "(...)" << std::endl; + FTSERVER_DEBUG() << " hash : " << hash << std::endl; + FTSERVER_DEBUG() << " encryption key : " << RsUtil::BinToHex(encryption_key,32) << std::endl; + FTSERVER_DEBUG() << " random nonce : " << RsUtil::BinToHex(initialization_vector,ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE) << std::endl; +#endif offset += ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE ; @@ -1248,7 +1262,7 @@ bool ftServer::decryptItem(RsTurtleGenericDataItem *encrypted_item,const RsFileH if(edata_size + ENCRYPTED_FT_EDATA_SIZE + ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_HEADER_SIZE != encrypted_item->data_size) { - std::cerr << " ERROR: encrypted data size is " << edata_size << ", should be " << encrypted_item->data_size - (ENCRYPTED_FT_EDATA_SIZE + ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_HEADER_SIZE ) << std::endl; + FTSERVER_ERROR() << " ERROR: encrypted data size is " << edata_size << ", should be " << encrypted_item->data_size - (ENCRYPTED_FT_EDATA_SIZE + ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_HEADER_SIZE ) << std::endl; return false ; } @@ -1256,7 +1270,9 @@ bool ftServer::decryptItem(RsTurtleGenericDataItem *encrypted_item,const RsFileH uint32_t clear_item_offset = offset ; uint32_t authentication_tag_offset = offset + edata_size ; - std::cerr << " authen. tag : " << RsUtil::BinToHex(&edata[authentication_tag_offset],ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE) << std::endl; +#ifdef SERVER_DEBUG + FTSERVER_DEBUG() << " authen. tag : " << RsUtil::BinToHex(&edata[authentication_tag_offset],ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE) << std::endl; +#endif bool result ; @@ -1267,12 +1283,14 @@ bool ftServer::decryptItem(RsTurtleGenericDataItem *encrypted_item,const RsFileH else return false ; - std::cerr << " authen. result : " << result << std::endl; - std::cerr << " decrypted daya : " << RsUtil::BinToHex(&edata[clear_item_offset],std::min(50u,edata_size)) << "(...)" << std::endl; +#ifdef SERVER_DEBUG + FTSERVER_DEBUG() << " authen. result : " << result << std::endl; + FTSERVER_DEBUG() << " decrypted daya : " << RsUtil::BinToHex(&edata[clear_item_offset],std::min(50u,edata_size)) << "(...)" << std::endl; +#endif if(!result) { - std::cerr << "(EE) decryption/authentication went wrong." << std::endl; + FTSERVER_ERROR() << "(EE) decryption/authentication went wrong." << std::endl; return false ; } @@ -1328,20 +1346,22 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i, { if(i->PacketSubType() == RS_TURTLE_SUBTYPE_GENERIC_DATA) { - std::cerr << "Received encrypted data item. Trying to decrypt" << std::endl; +#ifdef SERVER_DEBUG + FTSERVER_DEBUG() << "Received encrypted data item. Trying to decrypt" << std::endl; +#endif RsFileHash real_hash ; if(!findRealHash(hash,real_hash)) { - std::cerr << "(EE) Cannot find real hash for encrypted data item with H(H(F))=" << hash << ". This is unexpected." << std::endl; + FTSERVER_ERROR() << "(EE) Cannot find real hash for encrypted data item with H(H(F))=" << hash << ". This is unexpected." << std::endl; return ; } RsTurtleGenericTunnelItem *decrypted_item ; if(!decryptItem(dynamic_cast(i),real_hash,decrypted_item)) { - std::cerr << "(EE) decryption error." << std::endl; + FTSERVER_ERROR() << "(EE) decryption error." << std::endl; return ; } @@ -1359,7 +1379,7 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i, if (item) { #ifdef SERVER_DEBUG - std::cerr << "ftServer::receiveTurtleData(): received file data request for " << hash << " from peer " << virtual_peer_id << std::endl; + FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received file data request for " << hash << " from peer " << virtual_peer_id << std::endl; #endif getMultiplexer()->recvDataRequest(virtual_peer_id,hash,0,item->chunk_offset,item->chunk_size) ; } @@ -1372,7 +1392,7 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i, if (item) { #ifdef SERVER_DEBUG - std::cerr << "ftServer::receiveTurtleData(): received file data for " << hash << " from peer " << virtual_peer_id << std::endl; + FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received file data for " << hash << " from peer " << virtual_peer_id << std::endl; #endif getMultiplexer()->recvData(virtual_peer_id,hash,0,item->chunk_offset,item->chunk_size,item->chunk_data) ; @@ -1388,7 +1408,7 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i, if (item) { #ifdef SERVER_DEBUG - std::cerr << "ftServer::receiveTurtleData(): received chunk map for hash " << hash << " from peer " << virtual_peer_id << std::endl; + FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received chunk map for hash " << hash << " from peer " << virtual_peer_id << std::endl; #endif getMultiplexer()->recvChunkMap(virtual_peer_id,hash,item->compressed_map,direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ; } @@ -1399,7 +1419,7 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i, { //RsTurtleFileMapRequestItem *item = dynamic_cast(i) ; #ifdef SERVER_DEBUG - std::cerr << "ftServer::receiveTurtleData(): received chunkmap request for hash " << hash << " from peer " << virtual_peer_id << std::endl; + FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received chunkmap request for hash " << hash << " from peer " << virtual_peer_id << std::endl; #endif getMultiplexer()->recvChunkMapRequest(virtual_peer_id,hash,direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ; } @@ -1411,7 +1431,7 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i, if (item) { #ifdef SERVER_DEBUG - std::cerr << "ftServer::receiveTurtleData(): received single chunk CRC for hash " << hash << " from peer " << virtual_peer_id << std::endl; + FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received single chunk CRC for hash " << hash << " from peer " << virtual_peer_id << std::endl; #endif getMultiplexer()->recvSingleChunkCRC(virtual_peer_id,hash,item->chunk_number,item->check_sum) ; } @@ -1424,14 +1444,14 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i, if (item) { #ifdef SERVER_DEBUG - std::cerr << "ftServer::receiveTurtleData(): received single chunk CRC request for hash " << hash << " from peer " << virtual_peer_id << std::endl; + FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received single chunk CRC request for hash " << hash << " from peer " << virtual_peer_id << std::endl; #endif getMultiplexer()->recvSingleChunkCRCRequest(virtual_peer_id,hash,item->chunk_number) ; } } break ; default: - std::cerr << "WARNING: Unknown packet type received: sub_id=" << reinterpret_cast(i->PacketSubType()) << ". Is somebody trying to poison you ?" << std::endl ; + FTSERVER_ERROR() << "WARNING: Unknown packet type received: sub_id=" << reinterpret_cast(i->PacketSubType()) << ". Is somebody trying to poison you ?" << std::endl ; } } @@ -1480,7 +1500,7 @@ int ftServer::handleIncoming() if (f) { #ifdef SERVER_DEBUG - std::cerr << "ftServer::handleIncoming: received data request for hash " << f->file.hash << ", offset=" << f->fileoffset << ", chunk size=" << f->chunksize << std::endl; + FTSERVER_DEBUG() << "ftServer::handleIncoming: received data request for hash " << f->file.hash << ", offset=" << f->fileoffset << ", chunk size=" << f->chunksize << std::endl; #endif mFtDataplex->recvDataRequest(f->PeerId(), f->file.hash, f->file.filesize, f->fileoffset, f->chunksize); } @@ -1493,7 +1513,7 @@ int ftServer::handleIncoming() if (f) { #ifdef SERVER_DEBUG - std::cerr << "ftServer::handleIncoming: received data for hash " << f->fd.file.hash << ", offset=" << f->fd.file_offset << ", chunk size=" << f->fd.binData.bin_len << std::endl; + FTSERVER_DEBUG() << "ftServer::handleIncoming: received data for hash " << f->fd.file.hash << ", offset=" << f->fd.file_offset << ", chunk size=" << f->fd.binData.bin_len << std::endl; #endif mFtDataplex->recvData(f->PeerId(), f->fd.file.hash, f->fd.file.filesize, f->fd.file_offset, f->fd.binData.bin_len, f->fd.binData.bin_data); @@ -1510,7 +1530,7 @@ int ftServer::handleIncoming() if (f) { #ifdef SERVER_DEBUG - std::cerr << "ftServer::handleIncoming: received chunkmap request for hash " << f->hash << ", client=" << f->is_client << std::endl; + FTSERVER_DEBUG() << "ftServer::handleIncoming: received chunkmap request for hash " << f->hash << ", client=" << f->is_client << std::endl; #endif mFtDataplex->recvChunkMapRequest(f->PeerId(), f->hash,f->is_client) ; } @@ -1523,7 +1543,7 @@ int ftServer::handleIncoming() if (f) { #ifdef SERVER_DEBUG - std::cerr << "ftServer::handleIncoming: received chunkmap for hash " << f->hash << ", client=" << f->is_client << /*", map=" << f->compressed_map <<*/ std::endl; + FTSERVER_DEBUG() << "ftServer::handleIncoming: received chunkmap for hash " << f->hash << ", client=" << f->is_client << /*", map=" << f->compressed_map <<*/ std::endl; #endif mFtDataplex->recvChunkMap(f->PeerId(), f->hash,f->compressed_map,f->is_client) ; } @@ -1536,7 +1556,7 @@ int ftServer::handleIncoming() if (f) { #ifdef SERVER_DEBUG - std::cerr << "ftServer::handleIncoming: received single chunk crc req for hash " << f->hash << ", chunk number=" << f->chunk_number << std::endl; + FTSERVER_DEBUG() << "ftServer::handleIncoming: received single chunk crc req for hash " << f->hash << ", chunk number=" << f->chunk_number << std::endl; #endif mFtDataplex->recvSingleChunkCRCRequest(f->PeerId(), f->hash,f->chunk_number) ; } @@ -1549,7 +1569,7 @@ int ftServer::handleIncoming() if (f) { #ifdef SERVER_DEBUG - std::cerr << "ftServer::handleIncoming: received single chunk crc req for hash " << f->hash << ", chunk number=" << f->chunk_number << ", checksum = " << f->check_sum << std::endl; + FTSERVER_DEBUG() << "ftServer::handleIncoming: received single chunk crc req for hash " << f->hash << ", chunk number=" << f->chunk_number << ", checksum = " << f->check_sum << std::endl; #endif mFtDataplex->recvSingleChunkCRC(f->PeerId(), f->hash,f->chunk_number,f->check_sum); } diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index 5d17da77e..76b030cb5 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -157,6 +157,7 @@ public: virtual bool FileDetails(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info); virtual bool FileDownloadChunksDetails(const RsFileHash& hash,FileChunksInfo& info) ; virtual bool FileUploadChunksDetails(const RsFileHash& hash,const RsPeerId& peer_id,CompressedChunkMap& map) ; + virtual bool isEncryptedSource(const RsPeerId& virtual_peer_id) ; /*** diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index 18036c52a..5b888d1c3 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -166,6 +166,7 @@ class RsFiles virtual void FileDownloads(std::list &hashs) = 0; virtual bool FileUploads(std::list &hashs) = 0; virtual bool FileDetails(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) = 0; + virtual bool isEncryptedSource(const RsPeerId& virtual_peer_id) =0; /// Gives chunk details about the downloaded file with given hash. virtual bool FileDownloadChunksDetails(const RsFileHash& hash,FileChunksInfo& info) = 0 ; diff --git a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp index 195959e16..13af37646 100644 --- a/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/FileTransfer/TransfersDialog.cpp @@ -1387,7 +1387,12 @@ QString TransfersDialog::getPeerName(const RsPeerId& id) const // connect mgr). In such a case their id can suitably hold for a name. // if(res == "") + { + if(rsFiles->isEncryptedSource(id)) + return tr("Anonymous end-to-end encrypted tunnel 0x")+QString::fromStdString(id.toStdString()).left(8) ; + else return tr("Anonymous tunnel 0x")+QString::fromStdString(id.toStdString()).left(8) ; + } else return res ; } From 05b5c08e9fbf0be54933477a06b60c9e47b844df Mon Sep 17 00:00:00 2001 From: hunbernd Date: Sat, 10 Sep 2016 21:59:45 +0200 Subject: [PATCH 18/52] Fixed emoticon order --- retroshare-gui/src/gui/common/Emoticons.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/retroshare-gui/src/gui/common/Emoticons.cpp b/retroshare-gui/src/gui/common/Emoticons.cpp index d905c5559..3894c9deb 100644 --- a/retroshare-gui/src/gui/common/Emoticons.cpp +++ b/retroshare-gui/src/gui/common/Emoticons.cpp @@ -34,6 +34,7 @@ #include "util/HandleRichText.h" static QHash Smileys; +static QVector order; void Emoticons::load() { @@ -115,6 +116,7 @@ void Emoticons::load() } else { Smileys.insert(smcode, smfile); } + order.append(smcode); } } @@ -174,15 +176,15 @@ void Emoticons::showSmileyWidget(QWidget *parent, QWidget *button, const char *s x = 0; y = 0; - QHashIterator i(Smileys); + QVectorIterator i(order); while(i.hasNext()) { - i.next(); + QString key = i.next(); QPushButton *smButton = new QPushButton("", smWidget); smButton->setGeometry(x*buttonWidth, y*buttonHeight, buttonWidth, buttonHeight); smButton->setIconSize(QSize(buttonWidth, buttonHeight)); - smButton->setIcon(QPixmap(i.value())); - smButton->setToolTip(i.key()); + smButton->setIcon(QPixmap(Smileys.value(key))); + smButton->setToolTip(key); smButton->setStyleSheet("QPushButton:hover {border: 3px solid white; border-radius: 2px;}"); smButton->setFlat(true); ++x; From 36dc532da6caf63c85b6b87722aa29065d470be8 Mon Sep 17 00:00:00 2001 From: hunbernd Date: Mon, 31 Oct 2016 00:23:39 +0100 Subject: [PATCH 19/52] Automatically detect retroshare links when pasting text --- retroshare-gui/src/gui/RetroShareLink.cpp | 83 ++++++++++--------- retroshare-gui/src/gui/RetroShareLink.h | 2 + .../src/gui/common/MimeTextEdit.cpp | 11 +++ 3 files changed, 57 insertions(+), 39 deletions(-) diff --git a/retroshare-gui/src/gui/RetroShareLink.cpp b/retroshare-gui/src/gui/RetroShareLink.cpp index 5aa195373..957b61f7f 100644 --- a/retroshare-gui/src/gui/RetroShareLink.cpp +++ b/retroshare-gui/src/gui/RetroShareLink.cpp @@ -1587,46 +1587,8 @@ void RSLinkClipboard::parseClipboard(QList &links) { // parse clipboard for links. // - links.clear(); QString text = QApplication::clipboard()->text() ; - - std::cerr << "Parsing clipboard:" << text.toStdString() << std::endl ; - - QRegExp rx(QString("retroshare://(%1)[^\r\n]+").arg(HOST_REGEXP)); - - int pos = 0; - - while((pos = rx.indexIn(text, pos)) != -1) - { - QString url(text.mid(pos, rx.matchedLength())); - RetroShareLink link(url); - - if(link.valid()) - { - // check that the link is not already in the list: - bool already = false ; - for (int i = 0; i &links) +{ + links.clear(); + + std::cerr << "Parsing text:" << text.toStdString() << std::endl ; + + QRegExp rx(QString("retroshare://(%1)[^\r\n]+").arg(HOST_REGEXP)); + + int pos = 0; + + while((pos = rx.indexIn(text, pos)) != -1) + { + QString url(text.mid(pos, rx.matchedLength())); + RetroShareLink link(url); + + if(link.valid()) + { + // check that the link is not already in the list: + bool already = false ; + for (int i = 0; i &links) ; + private: static void parseClipboard(QList &links) ; }; diff --git a/retroshare-gui/src/gui/common/MimeTextEdit.cpp b/retroshare-gui/src/gui/common/MimeTextEdit.cpp index 79ae8de56..5ff657ce3 100644 --- a/retroshare-gui/src/gui/common/MimeTextEdit.cpp +++ b/retroshare-gui/src/gui/common/MimeTextEdit.cpp @@ -78,6 +78,17 @@ void MimeTextEdit::insertFromMimeData(const QMimeData* source) } #endif + //insert retroshare links + QList links; + RSLinkClipboard::parseText(source->text(), links); + if(links.size() > 0) + { + for(int i = 0; i < links.size(); ++i) + insertHtml(links[i].toHtml() + "
"); + + return; + } + return RSTextEdit::insertFromMimeData(source); } From e8e054eeaec71e1441a6ce26469b99e6675fe321 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Mon, 31 Oct 2016 14:26:01 +0100 Subject: [PATCH 20/52] addednew flag for anonymous search. Merged the two browsable flags in one single flag. --- libretroshare/src/file_sharing/p3filelists.cc | 3 +- libretroshare/src/ft/ftcontroller.cc | 2 +- libretroshare/src/ft/ftextralist.cc | 5 +- libretroshare/src/ft/ftserver.cc | 4 +- libretroshare/src/retroshare/rstypes.h | 13 +- libretroshare/src/rsserver/p3peers.cc | 6 +- retroshare-gui/src/gui/QuickStartWizard.cpp | 10 +- retroshare-gui/src/gui/RemoteDirModel.cpp | 7 +- retroshare-gui/src/gui/ShareDialog.cpp | 2 +- .../src/gui/common/GroupFlagsWidget.cpp | 154 +++++++----------- .../src/gui/common/GroupFlagsWidget.h | 7 +- retroshare-gui/src/gui/icons.qrc | 8 +- retroshare-gui/src/gui/icons/make_qrc_file.sh | 2 +- retroshare-nogui/src/menu/menus.cc | 4 +- 14 files changed, 99 insertions(+), 128 deletions(-) diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index bad026bbf..7aa9c5316 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -338,7 +338,7 @@ bool p3FileDatabase::loadList(std::list& load) /* for each item, check it exists .... * - remove any that are dead (or flag?) */ - static const FileStorageFlags PERMISSION_MASK = DIR_FLAGS_BROWSABLE_OTHERS | DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_GROUPS | DIR_FLAGS_NETWORK_WIDE_GROUPS ; + static const FileStorageFlags PERMISSION_MASK = DIR_FLAGS_PERMISSIONS_MASK; #ifdef DEBUG_FILE_HIERARCHY P3FILELISTS_DEBUG() << "Load list" << std::endl; @@ -388,7 +388,6 @@ bool p3FileDatabase::loadList(std::list& load) info.virtualname = fi->file.name; info.shareflags = FileStorageFlags(fi->flags) ; info.shareflags &= PERMISSION_MASK ; - info.shareflags &= ~DIR_FLAGS_NETWORK_WIDE_GROUPS ; // disabling this flag for know, for consistency reasons for(std::set::const_iterator itt(fi->parent_groups.ids.begin());itt!=fi->parent_groups.ids.end();++itt) info.parent_groups.push_back(*itt) ; diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index 6e0bbccbd..fe6ada159 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -1611,7 +1611,7 @@ bool ftController::FileDetails(const RsFileHash &hash, FileInfo &info) info.queue_position = it->second->mQueuePosition ; if(it->second->mFlags & RS_FILE_REQ_ANONYMOUS_ROUTING) - info.storage_permission_flags |= DIR_FLAGS_NETWORK_WIDE_OTHERS ; // file being downloaded anonymously are always anonymously available. + info.storage_permission_flags |= DIR_FLAGS_ANONYMOUS_DOWNLOAD ; // file being downloaded anonymously are always anonymously available. /* get list of sources from transferModule */ std::list peerIds; diff --git a/libretroshare/src/ft/ftextralist.cc b/libretroshare/src/ft/ftextralist.cc index 094e07c8d..84ba0692b 100644 --- a/libretroshare/src/ft/ftextralist.cc +++ b/libretroshare/src/ft/ftextralist.cc @@ -350,9 +350,10 @@ bool ftExtraList::search(const RsFileHash &hash, FileSearchFlags /*hintflags* // Now setup the file storage flags so that the client can know how to handle permissions // - info.storage_permission_flags = DIR_FLAGS_BROWSABLE_OTHERS ; +#warning make sure this is right + info.storage_permission_flags = FileStorageFlags(0) ;//DIR_FLAGS_BROWSABLE_OTHERS ; - if(info.transfer_info_flags & RS_FILE_REQ_ANONYMOUS_ROUTING) info.storage_permission_flags |= DIR_FLAGS_NETWORK_WIDE_OTHERS ; + if(info.transfer_info_flags & RS_FILE_REQ_ANONYMOUS_ROUTING) info.storage_permission_flags |= DIR_FLAGS_ANONYMOUS_DOWNLOAD ; return true; } diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 3b0b8d3f8..62d24a8d9 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -644,7 +644,7 @@ int ftServer::RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags { return mFileDatabase->RequestDirDetails(ref,details,flags) ; } -uint32_t ftServer::getType(void *ref, FileSearchFlags flags) +uint32_t ftServer::getType(void *ref, FileSearchFlags /* flags */) { return mFileDatabase->getType(ref) ; } @@ -797,7 +797,7 @@ bool ftServer::shareDownloadDirectory(bool share) /* Share */ SharedDirInfo inf ; inf.filename = mFtController->getDownloadDirectory(); - inf.shareflags = DIR_FLAGS_NETWORK_WIDE_OTHERS ; + inf.shareflags = DIR_FLAGS_ANONYMOUS_DOWNLOAD ; return addSharedDirectory(inf); } diff --git a/libretroshare/src/retroshare/rstypes.h b/libretroshare/src/retroshare/rstypes.h index 0a8537bb7..aef2d118e 100644 --- a/libretroshare/src/retroshare/rstypes.h +++ b/libretroshare/src/retroshare/rstypes.h @@ -155,12 +155,13 @@ const FileStorageFlags DIR_FLAGS_PARENT ( 0x0001 ); const FileStorageFlags DIR_FLAGS_DETAILS ( 0x0002 ); // apparently unused const FileStorageFlags DIR_FLAGS_CHILDREN ( 0x0004 ); // apparently unused -const FileStorageFlags DIR_FLAGS_NETWORK_WIDE_OTHERS ( 0x0080 ); // Flags for directory sharing permissions. The last -const FileStorageFlags DIR_FLAGS_BROWSABLE_OTHERS ( 0x0100 ); // one should be the OR of the all four flags. -const FileStorageFlags DIR_FLAGS_NETWORK_WIDE_GROUPS ( 0x0200 ); -const FileStorageFlags DIR_FLAGS_BROWSABLE_GROUPS ( 0x0400 ); -const FileStorageFlags DIR_FLAGS_PERMISSIONS_MASK ( DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_OTHERS - | DIR_FLAGS_NETWORK_WIDE_GROUPS | DIR_FLAGS_BROWSABLE_GROUPS ); +const FileStorageFlags DIR_FLAGS_ANONYMOUS_DOWNLOAD ( 0x0080 ); // Flags for directory sharing permissions. The last +//const FileStorageFlags DIR_FLAGS_BROWSABLE_OTHERS ( 0x0100 ); // one should be the OR of the all four flags. +//const FileStorageFlags DIR_FLAGS_NETWORK_WIDE_GROUPS ( 0x0200 ); +const FileStorageFlags DIR_FLAGS_BROWSABLE ( 0x0400 ); +const FileStorageFlags DIR_FLAGS_ANONYMOUS_SEARCH ( 0x0800 ); +const FileStorageFlags DIR_FLAGS_PERMISSIONS_MASK ( DIR_FLAGS_ANONYMOUS_DOWNLOAD | /*DIR_FLAGS_BROWSABLE_OTHERS + DIR_FLAGS_NETWORK_WIDE_GROUPS*/ DIR_FLAGS_BROWSABLE | DIR_FLAGS_ANONYMOUS_SEARCH); const FileStorageFlags DIR_FLAGS_LOCAL ( 0x1000 ); const FileStorageFlags DIR_FLAGS_REMOTE ( 0x2000 ); diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index bd4e11cbd..aea128867 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -1359,7 +1359,7 @@ FileSearchFlags p3Peers::computePeerPermissionFlags(const RsPeerId& peer_ssl_id, // very simple algorithm. // - bool found = false ; + bool found = directory_parent_groups.empty() ; // by default, empty list means browsable by everyone. RsPgpId pgp_id = getGPGId(peer_ssl_id) ; for(std::list::const_iterator it(directory_parent_groups.begin());it!=directory_parent_groups.end() && !found;++it) @@ -1378,8 +1378,8 @@ FileSearchFlags p3Peers::computePeerPermissionFlags(const RsPeerId& peer_ssl_id, // found = true ; } - bool network_wide = (share_flags & DIR_FLAGS_NETWORK_WIDE_OTHERS) ;//|| ( (share_flags & DIR_FLAGS_NETWORK_WIDE_GROUPS) && found) ; - bool browsable = (share_flags & DIR_FLAGS_BROWSABLE_OTHERS) || ( (share_flags & DIR_FLAGS_BROWSABLE_GROUPS) && found) ; + bool network_wide = (share_flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD) ;//|| ( (share_flags & DIR_FLAGS_NETWORK_WIDE_GROUPS) && found) ; + bool browsable = (share_flags & DIR_FLAGS_BROWSABLE) && found ; FileSearchFlags final_flags ; diff --git a/retroshare-gui/src/gui/QuickStartWizard.cpp b/retroshare-gui/src/gui/QuickStartWizard.cpp index 08f314959..bbed898d5 100644 --- a/retroshare-gui/src/gui/QuickStartWizard.cpp +++ b/retroshare-gui/src/gui/QuickStartWizard.cpp @@ -235,7 +235,7 @@ void QuickStartWizard::on_pushButtonSharesAdd_clicked() { SharedDirInfo sdi ; sdi.filename = dir ; - sdi.shareflags = DIR_FLAGS_BROWSABLE_OTHERS | DIR_FLAGS_NETWORK_WIDE_OTHERS ; + sdi.shareflags = DIR_FLAGS_BROWSABLE | DIR_FLAGS_ANONYMOUS_DOWNLOAD ; rsFiles->addSharedDirectory(sdi); @@ -331,8 +331,8 @@ void QuickStartWizard::loadShare() QCheckBox *cb1 = new QCheckBox ; QCheckBox *cb2 = new QCheckBox ; - cb1->setChecked( (*it).shareflags & DIR_FLAGS_NETWORK_WIDE_OTHERS ) ; - cb2->setChecked( (*it).shareflags & DIR_FLAGS_BROWSABLE_OTHERS ) ; + cb1->setChecked( (*it).shareflags & DIR_FLAGS_ANONYMOUS_DOWNLOAD ) ; + cb2->setChecked( (*it).shareflags & DIR_FLAGS_BROWSABLE ) ; cb1->setToolTip(tr("If checked, the share is anonymously shared to anybody.")) ; cb2->setToolTip(tr("If checked, the share is browsable by your friends.")) ; @@ -364,8 +364,8 @@ void QuickStartWizard::updateFlags(bool b) { std::cerr << "Looking for row=" << row << ", file=" << (*it).filename << ", flags=" << (*it).shareflags << std::endl ; FileStorageFlags current_flags(0u) ; - current_flags |= (dynamic_cast(ui.shareddirList->cellWidget(row,1)))->isChecked()? DIR_FLAGS_NETWORK_WIDE_OTHERS:(FileStorageFlags)0u ; - current_flags |= (dynamic_cast(ui.shareddirList->cellWidget(row,2)))->isChecked()? DIR_FLAGS_BROWSABLE_OTHERS :(FileStorageFlags)0u ; + current_flags |= (dynamic_cast(ui.shareddirList->cellWidget(row,1)))->isChecked()? DIR_FLAGS_ANONYMOUS_DOWNLOAD:(FileStorageFlags)0u ; + current_flags |= (dynamic_cast(ui.shareddirList->cellWidget(row,2)))->isChecked()? DIR_FLAGS_BROWSABLE :(FileStorageFlags)0u ; if( ((*it).shareflags ^ current_flags).toUInt32() ) { diff --git a/retroshare-gui/src/gui/RemoteDirModel.cpp b/retroshare-gui/src/gui/RemoteDirModel.cpp index bfe7e2dbe..250eadfe4 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.cpp +++ b/retroshare-gui/src/gui/RemoteDirModel.cpp @@ -216,10 +216,9 @@ QString RetroshareDirModel::getFlagsString(FileStorageFlags flags) { char str[11] = "- - -" ; - if(flags & DIR_FLAGS_BROWSABLE_GROUPS) str[0] = 'B' ; - //if(flags & DIR_FLAGS_NETWORK_WIDE_GROUPS) str[3] = 'N' ; - if(flags & DIR_FLAGS_BROWSABLE_OTHERS) str[3] = 'B' ; - if(flags & DIR_FLAGS_NETWORK_WIDE_OTHERS) str[6] = 'N' ; + if(flags & DIR_FLAGS_BROWSABLE) str[0] = 'B' ; + if(flags & DIR_FLAGS_ANONYMOUS_SEARCH) str[3] = 'S' ; + if(flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD) str[6] = 'N' ; return QString(str) ; } diff --git a/retroshare-gui/src/gui/ShareDialog.cpp b/retroshare-gui/src/gui/ShareDialog.cpp index 2f7ebcffe..6c4287888 100644 --- a/retroshare-gui/src/gui/ShareDialog.cpp +++ b/retroshare-gui/src/gui/ShareDialog.cpp @@ -57,7 +57,7 @@ ShareDialog::ShareDialog(std::string filename, QWidget *parent) hb2->addWidget(new QLabel(tr("Share flags and groups:")+" ")) ; groupflagsbox = new GroupFlagsWidget(ui.shareflags_GB) ; - groupflagsbox->setFlags(DIR_FLAGS_NETWORK_WIDE_OTHERS) ; // default value + groupflagsbox->setFlags(DIR_FLAGS_ANONYMOUS_DOWNLOAD) ; // default value messageBox = new QTextEdit(ui.shareflags_GB) ; messageBox->setReadOnly(true) ; diff --git a/retroshare-gui/src/gui/common/GroupFlagsWidget.cpp b/retroshare-gui/src/gui/common/GroupFlagsWidget.cpp index a86703fc7..ac8969690 100644 --- a/retroshare-gui/src/gui/common/GroupFlagsWidget.cpp +++ b/retroshare-gui/src/gui/common/GroupFlagsWidget.cpp @@ -3,31 +3,26 @@ #include "GroupFlagsWidget.h" #include -#define FLAGS_GROUP_NETWORK_WIDE_ICON ":images/anonymous_128_green.png" -#define FLAGS_GROUP_BROWSABLE_ICON ":images/browsable_128_green.png" -#define FLAGS_GROUP_UNCHECKED ":images/blank_128_green.png" -#define FLAGS_OTHER_NETWORK_WIDE_ICON ":images/anonymous_128_blue.png" -#define FLAGS_OTHER_BROWSABLE_ICON ":images/browsable_128_blue.png" -#define FLAGS_OTHER_UNCHECKED ":images/blank_128_blue.png" +#define FLAGS_ANONYMOUS_SEARCH_ON ":icons/search_red_128.png" +#define FLAGS_ANONYMOUS_SEARCH_OFF ":icons/blank_red_128.png" +#define FLAGS_BROWSABLE_ON ":icons/browsable_green_128.png" +#define FLAGS_BROWSABLE_OFF ":icons/blank_green_128.png" +#define FLAGS_ANONYMOUS_DL_ON ":icons/anonymous_blue_128.png" +#define FLAGS_ANONYMOUS_DL_OFF ":icons/blank_blue_128.png" -#define INDEX_GROUP_BROWSABLE 0 -#define INDEX_GROUP_NETWORK_W 1 -#define INDEX_OTHER_BROWSABLE 2 -#define INDEX_OTHER_NETWORK_W 3 -#define INDEX_GROUP_UNCHECKED 4 -#define INDEX_OTHER_UNCHECKED 5 +#define INDEX_BROWSABLE 0 +#define INDEX_ANON_SEARCH 1 +#define INDEX_ANON_DL 2 /*QString GroupFlagsWidget::_tooltips_on[4] = { - QObject::tr("Directory is browsable for friends from groups"), - QObject::tr("Directory is accessible by anonymous tunnels from friends from groups"), - QObject::tr("Directory is browsable for any friend"), - QObject::tr("Directory is accessible by anonymous tunnels from any friend") + QObject::tr("Directory is visible to friends"), + QObject::tr("Directory can be search anonymously"), + QObject::tr("Directory is accessible by anonymous tunnels") }; QString GroupFlagsWidget::_tooltips_off[4] = { - QObject::tr("Directory is NOT browsable for friends from groups"), - QObject::tr("Directory is NOT accessible by anonymous tunnels from friends from groups"), - QObject::tr("Directory is NOT browsable for any friend"), - QObject::tr("Directory is NOT accessible by anonymous tunnels from any friend") + QObject::tr("Directory is not visible to friends"), + QObject::tr("Directory cannot be searched anonymously"), + QObject::tr("Directory is NOT accessible by anonymous tunnels") }; */ GroupFlagsWidget::GroupFlagsWidget(QWidget *parent,FileStorageFlags flags) @@ -39,35 +34,33 @@ GroupFlagsWidget::GroupFlagsWidget(QWidget *parent,FileStorageFlags flags) setMaximumSize(128 * QFontMetricsF(font()).height()/14.0,32 * QFontMetricsF(font()).height()/14.0) ; setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed); - _icons[INDEX_GROUP_BROWSABLE] = new QIcon(FLAGS_GROUP_BROWSABLE_ICON) ; - _icons[INDEX_GROUP_NETWORK_W] = new QIcon(FLAGS_GROUP_NETWORK_WIDE_ICON) ; - _icons[INDEX_OTHER_BROWSABLE] = new QIcon(FLAGS_OTHER_BROWSABLE_ICON) ; - _icons[INDEX_OTHER_NETWORK_W] = new QIcon(FLAGS_OTHER_NETWORK_WIDE_ICON) ; - _icons[INDEX_GROUP_UNCHECKED] = new QIcon(FLAGS_GROUP_UNCHECKED) ; - _icons[INDEX_OTHER_UNCHECKED] = new QIcon(FLAGS_OTHER_UNCHECKED) ; + _icons[2*INDEX_BROWSABLE+0] = new QIcon(FLAGS_BROWSABLE_OFF) ; + _icons[2*INDEX_BROWSABLE+1] = new QIcon(FLAGS_BROWSABLE_ON) ; + _icons[2*INDEX_ANON_SEARCH+0] = new QIcon(FLAGS_ANONYMOUS_SEARCH_OFF) ; + _icons[2*INDEX_ANON_SEARCH+1] = new QIcon(FLAGS_ANONYMOUS_SEARCH_ON) ; + _icons[2*INDEX_ANON_DL+0] = new QIcon(FLAGS_ANONYMOUS_DL_OFF) ; + _icons[2*INDEX_ANON_DL+1] = new QIcon(FLAGS_ANONYMOUS_DL_ON) ; setLayout(_layout) ; - _flags[0] = DIR_FLAGS_BROWSABLE_GROUPS ; - _flags[1] = DIR_FLAGS_NETWORK_WIDE_GROUPS ; - _flags[2] = DIR_FLAGS_BROWSABLE_OTHERS ; - _flags[3] = DIR_FLAGS_NETWORK_WIDE_OTHERS ; + _flags[INDEX_BROWSABLE ] = DIR_FLAGS_BROWSABLE ; + _flags[INDEX_ANON_SEARCH] = DIR_FLAGS_ANONYMOUS_SEARCH ; + _flags[INDEX_ANON_DL ] = DIR_FLAGS_ANONYMOUS_DOWNLOAD ; - for(int i=0;i<4;++i) + for(int i=0;i<3;++i) { _buttons[i] = new QPushButton(this) ; _buttons[i]->setCheckable(true) ; _buttons[i]->setChecked(flags & _flags[i]) ; _buttons[i]->setIconSize(QSize(32 * QFontMetricsF(font()).height()/14.0,32 * QFontMetricsF(font()).height()/14.0)); + update_button_state(_buttons[i]->isChecked(),i) ; _layout->addWidget(_buttons[i]) ; } - _buttons[INDEX_GROUP_NETWORK_W]->setHidden(true); - connect(_buttons[INDEX_GROUP_NETWORK_W],SIGNAL(toggled(bool)),this,SLOT(update_GN_button(bool))) ; - connect(_buttons[INDEX_OTHER_NETWORK_W],SIGNAL(toggled(bool)),this,SLOT(update_ON_button(bool))) ; - connect(_buttons[INDEX_GROUP_BROWSABLE],SIGNAL(toggled(bool)),this,SLOT(update_GB_button(bool))) ; - connect(_buttons[INDEX_OTHER_BROWSABLE],SIGNAL(toggled(bool)),this,SLOT(update_OB_button(bool))) ; + connect(_buttons[INDEX_ANON_DL ],SIGNAL(toggled(bool)),this,SLOT(update_DL_button(bool))) ; + connect(_buttons[INDEX_ANON_SEARCH],SIGNAL(toggled(bool)),this,SLOT(update_SR_button(bool))) ; + connect(_buttons[INDEX_BROWSABLE ],SIGNAL(toggled(bool)),this,SLOT(update_BR_button(bool))) ; _layout->setSpacing(0); _layout->setContentsMargins(0, 0, 0, 0); @@ -84,16 +77,15 @@ FileStorageFlags GroupFlagsWidget::flags() const { FileStorageFlags flags ; - for(int i=0;i<4;++i) + for(int i=0;i<3;++i) if(_buttons[i]->isChecked()) flags |= _flags[i] ; - flags &= ~DIR_FLAGS_NETWORK_WIDE_GROUPS ; return flags ; } void GroupFlagsWidget::setFlags(FileStorageFlags flags) { - for(int i=0;i<4;++i) + for(int i=0;i<3;++i) { _buttons[i]->setChecked(flags & _flags[i]) ; update_button_state(_buttons[i]->isChecked(),i) ; @@ -105,40 +97,23 @@ void GroupFlagsWidget::update_button_state(bool b,int button_id) QString tip_on, tip_off; switch (button_id) { case 0: - tip_on = tr("Directory is browsable for friends from groups"); - tip_off = tr("Directory is NOT browsable for friends from groups"); + tip_on = tr("Directory is visible to friends"); + tip_off = tr("Directory is NOT visible to friends"); break; case 1: - tip_on = tr("Directory is accessible by anonymous tunnels from friends from groups"); - tip_off = tr("Directory is NOT accessible by anonymous tunnels from friends from groups"); + tip_on = tr("Directory can be searched anonymously"); + tip_off = tr("Directory cannot be searched anonymously"); break; case 2: - tip_on = tr("Directory is browsable for any friend"); - tip_off = tr("Directory is NOT browsable for any friend"); - break; - case 3: - tip_on = tr("Directory is accessible by anonymous tunnels from any friend"); - tip_off = tr("Directory is NOT accessible by anonymous tunnels from any friend"); + tip_on = tr("Files can be downloaded anonymously"); + tip_off = tr("Files cannot be downloaded anonymously"); break; default: tip_on = ""; tip_off = ""; } - if(b) - { - _buttons[button_id]->setIcon(*_icons[button_id]) ; - _buttons[button_id]->setToolTip(tip_on) ; - } - else if(button_id == INDEX_GROUP_NETWORK_W || button_id == INDEX_GROUP_BROWSABLE) - { - _buttons[button_id]->setIcon(*_icons[INDEX_GROUP_UNCHECKED]) ; - _buttons[button_id]->setToolTip(tip_off) ; - } - else - { - _buttons[button_id]->setIcon(*_icons[INDEX_OTHER_UNCHECKED]) ; - _buttons[button_id]->setToolTip(tip_off) ; - } + _buttons[button_id]->setIcon(*_icons[2*button_id+(int)b]) ; + _buttons[button_id]->setToolTip(b?tip_on:tip_off) ; } QString GroupFlagsWidget::groupInfoString(FileStorageFlags flags, const QList& groupNames) @@ -155,42 +130,39 @@ QString GroupFlagsWidget::groupInfoString(FileStorageFlags flags, const QListicons/settings/sound.svg icons/settings/webinterface.svg icons/add_user_256.png - icons/anonymous_blue_128.png - icons/anonymous_green_128.png icons/aol.png icons/avatar_128.png icons/avatar_grey_128.png - icons/blank_blue_128.png + icons/blank_red_128.png icons/blank_green_128.png - icons/browsable_blue_128.png + icons/blank_blue_128.png icons/browsable_green_128.png + icons/search_red_128.png + icons/anonymous_blue_128.png icons/bullet_blue_128.png icons/bullet_green_128.png icons/bullet_grey_128.png diff --git a/retroshare-gui/src/gui/icons/make_qrc_file.sh b/retroshare-gui/src/gui/icons/make_qrc_file.sh index 970eed055..a958fc2b3 100755 --- a/retroshare-gui/src/gui/icons/make_qrc_file.sh +++ b/retroshare-gui/src/gui/icons/make_qrc_file.sh @@ -3,7 +3,7 @@ echo '' echo '\t' -for i in `ls *.png`; do +for i in `ls *.png */*png */*svg`; do echo '\t\ticons/'$i'' done diff --git a/retroshare-nogui/src/menu/menus.cc b/retroshare-nogui/src/menu/menus.cc index 299aeb665..3eeab4bae 100644 --- a/retroshare-nogui/src/menu/menus.cc +++ b/retroshare-nogui/src/menu/menus.cc @@ -656,7 +656,7 @@ int MenuListShared::getEntryDesc(int idx, std::string &desc) for (it = dirs.begin(); (i < idx) && (it != dirs.end()); it++, i++); if (it != dirs.end()) { - bool networkwide = (it->shareflags & DIR_FLAGS_NETWORK_WIDE_OTHERS); + bool networkwide = (it->shareflags & DIR_FLAGS_ANONYMOUS_DOWNLOAD); bool browsable = (it->shareflags & DIR_FLAGS_BROWSABLE_OTHERS); if (networkwide && browsable) { @@ -759,7 +759,7 @@ uint32_t MenuListSharedTogglePublic::op_basic(std::string key) return MENU_OP_ERROR; } - mls->toggleFlagSelected(DIR_FLAGS_NETWORK_WIDE_OTHERS); + mls->toggleFlagSelected(DIR_FLAGS_ANONYMOUS_DOWNLOAD); return MENU_OP_INSTANT; } From 9d586bcfb06ebd133eb70b11f5a56b6b993bdb39 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Mon, 31 Oct 2016 16:28:26 +0100 Subject: [PATCH 21/52] made a drastic simplification pass on the ShareManager, which now only needs a single window except for selecting files using a QFileDialog --- libretroshare/src/ft/ftserver.cc | 2 +- libretroshare/src/ft/ftserver.h | 2 +- libretroshare/src/retroshare/rsfiles.h | 7 +- retroshare-gui/src/gui/ShareManager.cpp | 280 ++++++++++-------- retroshare-gui/src/gui/ShareManager.h | 13 +- retroshare-gui/src/gui/ShareManager.ui | 72 ++--- .../src/gui/common/GroupSelectionBox.cpp | 39 ++- .../src/gui/common/GroupSelectionBox.h | 17 ++ .../src/gui/icons/blank_red_128.png | Bin 0 -> 6043 bytes .../src/gui/icons/search_red_128.png | Bin 0 -> 8931 bytes 10 files changed, 255 insertions(+), 177 deletions(-) create mode 100644 retroshare-gui/src/gui/icons/blank_red_128.png create mode 100644 retroshare-gui/src/gui/icons/search_red_128.png diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 62d24a8d9..38efb452e 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -700,7 +700,7 @@ bool ftServer::getSharedDirectories(std::list &dirs) return true; } -bool ftServer::setSharedDirectories(std::list &dirs) +bool ftServer::setSharedDirectories(const std::list& dirs) { mFileDatabase->setSharedDirectories(dirs); return true; diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index 76b030cb5..29be7aa90 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -202,7 +202,7 @@ public: virtual std::string getPartialsDirectory(); virtual bool getSharedDirectories(std::list &dirs); - virtual bool setSharedDirectories(std::list &dirs); + virtual bool setSharedDirectories(const std::list &dirs); virtual bool addSharedDirectory(const SharedDirInfo& dir); virtual bool updateShareFlags(const SharedDirInfo& dir); // updates the flags. The directory should already exist ! virtual bool removeSharedDirectory(std::string dir); diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index 5b888d1c3..c40ce9d54 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -101,7 +101,7 @@ struct SharedDirInfo { std::string filename ; std::string virtualname ; - FileStorageFlags shareflags ; // DIR_FLAGS_NETWORK_WIDE_OTHERS | DIR_FLAGS_BROWSABLE_GROUPS | ... + FileStorageFlags shareflags ; // combnation of DIR_FLAGS_ANONYMOUS_DOWNLOAD | DIR_FLAGS_BROWSABLE | ... std::list parent_groups ; }; @@ -217,8 +217,9 @@ class RsFiles virtual std::string getDownloadDirectory() = 0; virtual std::string getPartialsDirectory() = 0; - virtual bool getSharedDirectories(std::list &dirs) = 0; - virtual bool addSharedDirectory(const SharedDirInfo& dir) = 0; + virtual bool getSharedDirectories(std::list& dirs) = 0; + virtual bool setSharedDirectories(const std::list& dirs) = 0; + virtual bool addSharedDirectory(const SharedDirInfo& dir) = 0; virtual bool updateShareFlags(const SharedDirInfo& dir) = 0; // updates the flags. The directory should already exist ! virtual bool removeSharedDirectory(std::string dir) = 0; diff --git a/retroshare-gui/src/gui/ShareManager.cpp b/retroshare-gui/src/gui/ShareManager.cpp index 61aadefb4..878a54e30 100644 --- a/retroshare-gui/src/gui/ShareManager.cpp +++ b/retroshare-gui/src/gui/ShareManager.cpp @@ -34,7 +34,8 @@ #include "ShareManager.h" #include "ShareDialog.h" #include "settings/rsharesettings.h" -#include +#include "gui/common/GroupFlagsWidget.h" +#include "gui/common/GroupSelectionBox.h" #include "gui/common/GroupDefs.h" #include "gui/notifyqt.h" #include "util/QtVersion.h" @@ -65,18 +66,16 @@ ShareManager::ShareManager() Settings->loadWidgetInformation(this); - connect(ui.addButton, SIGNAL(clicked( bool ) ), this , SLOT( showShareDialog() ) ); - connect(ui.editButton, SIGNAL(clicked( bool ) ), this , SLOT( editShareDirectory() ) ); - connect(ui.removeButton, SIGNAL(clicked( bool ) ), this , SLOT( removeShareDirectory() ) ); + connect(ui.addButton, SIGNAL(clicked( bool ) ), this , SLOT( addShare() ) ); connect(ui.closeButton, SIGNAL(clicked()), this, SLOT(applyAndClose())); + connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(cancel())); connect(ui.shareddirList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(shareddirListCostumPopupMenu(QPoint))); connect(ui.shareddirList, SIGNAL(currentCellChanged(int,int,int,int)), this, SLOT(shareddirListCurrentCellChanged(int,int,int,int))); - connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(updateGroups())); + connect(ui.shareddirList, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(doubleClickedCell(int,int))); - ui.editButton->setEnabled(false); - ui.removeButton->setEnabled(false); + connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(reload())); QHeaderView* header = ui.shareddirList->horizontalHeader(); QHeaderView_setSectionResizeModeColumn(header, COLUMN_PATH, QHeaderView::Stretch); @@ -90,6 +89,33 @@ ShareManager::ShareManager() setAttribute(Qt::WA_DeleteOnClose, true); } +void ShareManager::doubleClickedCell(int row,int column) +{ + if(column == COLUMN_PATH) + { + QString dirname = QFileDialog::getExistingDirectory(NULL,tr("Choose directory"),QString(),QFileDialog::DontUseNativeDialog | QFileDialog::ShowDirsOnly); + + if(!dirname.isNull()) + { + std::string new_name( dirname.toUtf8() ); + + for(uint32_t i=0;i selected_groups = GroupSelectionDialog::selectGroups(std::list()) ; + + mDirInfos[row].parent_groups = selected_groups ; + load(); + } +} + ShareManager::~ShareManager() { _instance = NULL; @@ -97,11 +123,21 @@ ShareManager::~ShareManager() Settings->saveWidgetInformation(this); } +void ShareManager::cancel() +{ + close(); +} void ShareManager::applyAndClose() { -// std::cerr << "ShareManager:::close(): updating!" << std::endl; + // This is the only place where we change things. + + std::list infos ; + + for(uint32_t i=0;isetSharedDirectories(infos) ; - updateFlags() ; close() ; } @@ -121,6 +157,17 @@ void ShareManager::shareddirListCostumPopupMenu( QPoint /*point*/ ) contextMnu.exec(QCursor::pos()); } +void ShareManager::reload() +{ + std::list dirs ; + rsFiles->getSharedDirectories(dirs) ; + + for(std::list::const_iterator it(dirs.begin());it!=dirs.end();++it) + mDirInfos.push_back(*it) ; + + load(); +} + /** Loads the settings for this page */ void ShareManager::load() { @@ -128,44 +175,40 @@ void ShareManager::load() return ; isLoading = true; -// std::cerr << "ShareManager:: In load !!!!!" << std::endl ; - - std::list::const_iterator it; - std::list dirs; - rsFiles->getSharedDirectories(dirs); /* get a link to the table */ QTableWidget *listWidget = ui.shareddirList; /* set new row count */ - listWidget->setRowCount(dirs.size()); + listWidget->setRowCount(mDirInfos.size()); - int row=0 ; - for(it = dirs.begin(); it != dirs.end(); ++it,++row) + for(uint32_t row=0;rowsetItem(row, COLUMN_PATH, new QTableWidgetItem(QString::fromUtf8((*it).filename.c_str()))); - listWidget->setItem(row, COLUMN_VIRTUALNAME, new QTableWidgetItem(QString::fromUtf8((*it).virtualname.c_str()))); + listWidget->setItem(row, COLUMN_PATH, new QTableWidgetItem(QString::fromUtf8(mDirInfos[row].filename.c_str()))); + listWidget->setItem(row, COLUMN_VIRTUALNAME, new QTableWidgetItem(QString::fromUtf8(mDirInfos[row].virtualname.c_str()))); - GroupFlagsWidget *widget = new GroupFlagsWidget(NULL,(*it).shareflags); + GroupFlagsWidget *widget = new GroupFlagsWidget(NULL,mDirInfos[row].shareflags); - listWidget->setRowHeight(row, 32 * QFontMetricsF(font()).height()/14.0); - listWidget->setCellWidget(row, COLUMN_SHARE_FLAGS, widget); + listWidget->setRowHeight(row, 32 * QFontMetricsF(font()).height()/14.0); + listWidget->setCellWidget(row, COLUMN_SHARE_FLAGS, widget); - listWidget->setItem(row, COLUMN_GROUPS, new QTableWidgetItem()) ; - listWidget->item(row,COLUMN_GROUPS)->setBackgroundColor(QColor(183,236,181)) ; + listWidget->setItem(row, COLUMN_GROUPS, new QTableWidgetItem()) ; + listWidget->item(row,COLUMN_GROUPS)->setBackgroundColor(QColor(183,236,181)) ; + listWidget->item(row,COLUMN_GROUPS)->setText(getGroupString(mDirInfos[row].parent_groups)); - //connect(widget,SIGNAL(flagsChanged(FileStorageFlags)),this,SLOT(updateFlags())) ; + connect(widget,SIGNAL(flagsChanged(FileStorageFlags)),this,SLOT(updateFlags())) ; + + listWidget->item(row,COLUMN_PATH)->setToolTip(tr("Double click to change shared directory path")) ; + listWidget->item(row,COLUMN_GROUPS)->setToolTip(tr("Double click to select which groups of friends can see the files")) ; + listWidget->item(row,COLUMN_VIRTUALNAME)->setToolTip(tr("Double click to change the cirtual file name")) ; } - listWidget->setColumnWidth(COLUMN_SHARE_FLAGS,132 * QFontMetricsF(font()).height()/14.0) ; - - //ui.incomingDir->setText(QString::fromStdString(rsFiles->getDownloadDirectory())); + listWidget->setColumnWidth(COLUMN_SHARE_FLAGS,132 * QFontMetricsF(font()).height()/14.0) ; listWidget->update(); /* update display */ update(); isLoading = false ; - updateGroups(); } void ShareManager::showYourself() @@ -173,6 +216,7 @@ void ShareManager::showYourself() if(_instance == NULL) _instance = new ShareManager() ; + _instance->reload() ; _instance->show() ; _instance->activateWindow(); } @@ -184,7 +228,7 @@ void ShareManager::showYourself() } if (update_local) { - _instance->load(); + _instance->reload(); } } @@ -193,101 +237,77 @@ void ShareManager::updateFlags() if(isLoading) return ; - isLoading = true ; // stops GUI update. Otherwise each call to rsFiles->updateShareFlags() modifies the GUI that we count on to check - // what has changed => fail! + isLoading = true ; // stops GUI update. Otherwise each call to rsFiles->updateShareFlags() modifies the GUI that we count on to check + // what has changed => fail! - // std::cerr << "Updating flags" << std::endl; + for(int row=0;rowrowCount();++row) + { + FileStorageFlags flags = (dynamic_cast(ui.shareddirList->cellWidget(row,COLUMN_SHARE_FLAGS)))->flags() ; - std::list::iterator it; - std::list dirs; - rsFiles->getSharedDirectories(dirs); - - std::map mapped_flags ; - - for(int row=0;rowrowCount();++row) - { - QString dirpath = ui.shareddirList->item(row,COLUMN_PATH)->text() ; - FileStorageFlags flags = (dynamic_cast(ui.shareddirList->cellWidget(row,COLUMN_SHARE_FLAGS)))->flags() ; - - mapped_flags[dirpath] = flags ; - -// std::cerr << "Getting new flags " << flags << " for path " << dirpath.toStdString() << std::endl; - } - - for(std::list::iterator it(dirs.begin());it!=dirs.end();++it) - { - FileStorageFlags newf = mapped_flags[QString::fromUtf8((*it).filename.c_str())] ; - - if( (*it).shareflags != newf ) - { - (*it).shareflags = newf ; - rsFiles->updateShareFlags(*it) ; // modifies the flags - -// std::cerr << "Updating flags to " << newf << " for dir " << (*it).filename << std::endl ; - } - } + mDirInfos[row].shareflags = flags ; + } isLoading = false ; // re-enable GUI load - load() ; // update the GUI. + load() ; // update the GUI. } -void ShareManager::updateGroups() +// void ShareManager::updateFromWidget() +// { +// mDirInfos.clear(); +// +// for(uint32_t i=0;iitem(i,COLUMN_PATH)->text().toUtf8() ; +// sdi.virtualname = ui.shareddirList->item(i,COLUMN_VIRTUALNAME)->text().toUtf8() ; +// sdi.shareflags = dynamic_cast(ui.shareddirList->item(i,COLUMN_SHARE_FLAGS))->flags(); +// sdi.parent_groups = std::list();//ui.shareddirList->item(i,COLUMN_GROUPS)->text(); +// } +// } + +QString ShareManager::getGroupString(const std::list& groups) { - if(isLoading) - return ; + int n = 0; + QString group_string ; -// std::cerr << "Updating groups" << std::endl; - - std::list::iterator it; - std::list dirs; - rsFiles->getSharedDirectories(dirs); - - int row=0 ; - for(it = dirs.begin(); it != dirs.end(); ++it,++row) + for (std::list::const_iterator it(groups.begin());it!=groups.end();++it,++n) { - QTableWidgetItem *item = ui.shareddirList->item(row, COLUMN_GROUPS); + if (n>0) + group_string += ", " ; - QString group_string; - int n = 0; - for (std::list::const_iterator it2((*it).parent_groups.begin());it2!=(*it).parent_groups.end();++it2,++n) - { - if (n>0) - group_string += ", " ; - - RsGroupInfo groupInfo; - rsPeers->getGroupInfo(*it2, groupInfo); - group_string += GroupDefs::name(groupInfo); - } - - item->setText(group_string); + RsGroupInfo groupInfo; + rsPeers->getGroupInfo(*it, groupInfo); + group_string += GroupDefs::name(groupInfo); } + + return group_string ; } -void ShareManager::editShareDirectory() -{ - /* id current dir */ - int row = ui.shareddirList->currentRow(); - QTableWidgetItem *item = ui.shareddirList->item(row, COLUMN_PATH); - - if (item) { - std::string filename = item->text().toUtf8().constData(); - - std::list dirs; - rsFiles->getSharedDirectories(dirs); - - std::list::const_iterator it; - for (it = dirs.begin(); it != dirs.end(); ++it) { - if (it->filename == filename) { - /* file name found, show dialog */ - ShareDialog sharedlg (it->filename, this); - sharedlg.setWindowTitle(tr("Edit Shared Folder")); - sharedlg.exec(); - load(); - break; - } - } - } -} +// void ShareManager::editShareDirectory() +// { +// /* id current dir */ +// int row = ui.shareddirList->currentRow(); +// QTableWidgetItem *item = ui.shareddirList->item(row, COLUMN_PATH); +// +// if (item) { +// std::string filename = item->text().toUtf8().constData(); +// +// std::list dirs; +// rsFiles->getSharedDirectories(dirs); +// +// std::list::const_iterator it; +// for (it = dirs.begin(); it != dirs.end(); ++it) { +// if (it->filename == filename) { +// /* file name found, show dialog */ +// ShareDialog sharedlg (it->filename, this); +// sharedlg.setWindowTitle(tr("Edit Shared Folder")); +// sharedlg.exec(); +// load(); +// break; +// } +// } +// } +// } void ShareManager::removeShareDirectory() { @@ -301,7 +321,9 @@ void ShareManager::removeShareDirectory() { if ((QMessageBox::question(this, tr("Warning!"),tr("Do you really want to stop sharing this directory ?"),QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes))== QMessageBox::Yes) { - rsFiles->removeSharedDirectory( qdir->text().toUtf8().constData()); + for(uint32_t i=row;i+1= 0) { - ui.editButton->setEnabled(true); - ui.removeButton->setEnabled(true); - } else { - ui.editButton->setEnabled(false); - ui.removeButton->setEnabled(false); - } } void ShareManager::dragEnterEvent(QDragEnterEvent *event) diff --git a/retroshare-gui/src/gui/ShareManager.h b/retroshare-gui/src/gui/ShareManager.h index 93cce9aee..c0b4a7474 100644 --- a/retroshare-gui/src/gui/ShareManager.h +++ b/retroshare-gui/src/gui/ShareManager.h @@ -26,6 +26,7 @@ #include #include +#include #include "ui_ShareManager.h" class ShareManager : public QDialog @@ -55,14 +56,18 @@ private slots: /** Create the context popup menu and it's submenus */ void shareddirListCurrentCellChanged(int currentRow, int currentColumn, int previousRow, int previousColumn); void shareddirListCostumPopupMenu( QPoint point ); + void addShare(); + void doubleClickedCell(int,int); void showShareDialog(); - void editShareDirectory(); + //void editShareDirectory(); void removeShareDirectory(); void updateFlags(); - void updateGroups(); - void applyAndClose() ; + void applyAndClose() ; + void cancel() ; + void reload() ; + static QString getGroupString(const std::list& groups); private: static ShareManager *_instance; bool isLoading; @@ -72,6 +77,8 @@ private: /** Qt Designer generated object */ Ui::ShareManager ui; + + std::vector mDirInfos ; }; #endif diff --git a/retroshare-gui/src/gui/ShareManager.ui b/retroshare-gui/src/gui/ShareManager.ui index 5bb73fd18..63b1a980b 100644 --- a/retroshare-gui/src/gui/ShareManager.ui +++ b/retroshare-gui/src/gui/ShareManager.ui @@ -18,7 +18,16 @@ :/images/logo/logo_16.png:/images/logo/logo_16.png
- + + 0 + + + 0 + + + 0 + + 0 @@ -49,7 +58,7 @@ 6 - + Shared Folder Manager @@ -64,7 +73,7 @@ Qt::CustomContextMenu - QAbstractItemView::NoEditTriggers + QAbstractItemView::DoubleClicked true @@ -92,12 +101,12 @@ - Directory + Shared directory - Virtual Folder + Visible name @@ -139,7 +148,7 @@ Add a Share Directory - Add + Add new @@ -149,35 +158,7 @@ - - - - - 0 - 0 - - - - - 200 - 200 - - - - Stop sharing selected Directory - - - Remove - - - - 16 - 16 - - - - - + Qt::Horizontal @@ -190,24 +171,14 @@ - + Apply and close - - - - Edit selected Shared Directory - - - Edit - - - - + @@ -290,6 +261,13 @@ + + + + Cancel + + +
diff --git a/retroshare-gui/src/gui/common/GroupSelectionBox.cpp b/retroshare-gui/src/gui/common/GroupSelectionBox.cpp index 2e0cc9c32..6ee32a64d 100644 --- a/retroshare-gui/src/gui/common/GroupSelectionBox.cpp +++ b/retroshare-gui/src/gui/common/GroupSelectionBox.cpp @@ -1,3 +1,5 @@ +#include +#include #include #include "GroupSelectionBox.h" #include "GroupDefs.h" @@ -17,7 +19,6 @@ GroupSelectionBox::GroupSelectionBox(QWidget *parent) // Fill with available groups fillGroups(); } - void GroupSelectionBox::fillGroups() { std::list selectedIds; @@ -78,3 +79,39 @@ void GroupSelectionBox::selectedGroupNames(QList &groupNames) const } } } + +std::list GroupSelectionDialog::selectGroups(const std::list& default_groups) +{ + GroupSelectionDialog gsd(NULL) ; + + gsd.mBox->setSelectedGroupIds(default_groups) ; + + gsd.exec(); + + std::list selected_groups ; + gsd.mBox->selectedGroupIds(selected_groups); + + return selected_groups ; +} + +GroupSelectionDialog::~GroupSelectionDialog() +{ + delete mBox ; +} +GroupSelectionDialog::GroupSelectionDialog(QWidget *parent) +{ + mBox = new GroupSelectionBox(this) ; + + QLayout *l = new QVBoxLayout ; + setLayout(l) ; + + QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + + connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); + connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); + + l->addWidget(mBox) ; + l->addWidget(buttonBox) ; + l->update() ; +} + diff --git a/retroshare-gui/src/gui/common/GroupSelectionBox.h b/retroshare-gui/src/gui/common/GroupSelectionBox.h index 4afc9cc94..70ad69fc4 100644 --- a/retroshare-gui/src/gui/common/GroupSelectionBox.h +++ b/retroshare-gui/src/gui/common/GroupSelectionBox.h @@ -1,4 +1,5 @@ #include +#include #include class GroupSelectionBox: public QListWidget @@ -8,6 +9,8 @@ class GroupSelectionBox: public QListWidget public: GroupSelectionBox(QWidget *parent); + static void selectGroups(const std::list& default_groups) ; + void selectedGroupIds(std::list &groupIds) const; void selectedGroupNames(QList &groupNames) const; @@ -16,3 +19,17 @@ public: private slots: void fillGroups(); }; + +class GroupSelectionDialog: public QDialog +{ + Q_OBJECT + +public: + GroupSelectionDialog(QWidget *parent) ; + virtual ~GroupSelectionDialog() ; + + static std::list selectGroups(const std::list& default_groups) ; + +private: + GroupSelectionBox *mBox ; +}; diff --git a/retroshare-gui/src/gui/icons/blank_red_128.png b/retroshare-gui/src/gui/icons/blank_red_128.png new file mode 100644 index 0000000000000000000000000000000000000000..19057766a023e7b89848ede18beaf7ad7efce2f5 GIT binary patch literal 6043 zcmV;M7i8#(P)Oz@Z0f2-7z;ux~O9+4z06=<WDR*FRcSTFz- zW=q650N5=6FiBTtNC2?60Km==3$g$R3;-}uh=nNt1bYBr$Ri_o0EC$U6h`t_Jn<{8 z5a%iY0C<_QJh>z}MS)ugEpZ1|S1ukX&Pf+56gFW3VVXcL!g-k)GJ!M?;PcD?0HBc- z5#WRK{dmp}uFlRjj{U%*%WZ25jX z{P*?XzTzZ-GF^d31o+^>%=Ap99M6&ogks$0k4OBs3;+Bb(;~!4V!2o<6ys46agIcq zjPo+3B8fthDa9qy|77CdEc*jK-!%ZRYCZvbku9iQV*~a}ClFY4z~c7+0P?$U!PF=S z1Au6Q;m>#f??3%Vpd|o+W=WE9003S@Bra6Svp>fO002awfhw>;8}z{#EWidF!3EsG z3;bXU&9EIRU@z1_9W=mEXoiz;4lcq~xDGvV5BgyU zp1~-*fe8db$Osc*A=-!mVv1NJjtCc-h4>-CNCXm#Bp}I%6j35eku^v$Qi@a{RY)E3 zJ#qp$hg?Rwkvqr$GJ^buyhkyVfwECO)C{#lxu`c9ghrwZ&}4KmnvWKso6vH!8a<3Q zq36)6Xb;+tK10Vaz~~qUGsJ8#F2=(`u{bOVlVi)VBCHIn#u~6ztOL7=^<&SmcLWlF zMZgI*1b0FpVIDz9SWH+>*hr`#93(Um+6gxa1B6k+CnA%mOSC4s5&6UzVlpv@SV$}* z))J2sFA#f(L&P^E5{W}HC%KRUNwK6<(h|}}(r!{C=`5+6G)NjFlgZj-YqAG9lq?`C z$c5yc>d>VnA`E_*3F2Qp##d8RZb=H01_mm@+|Cqnc9PsG(F5HIG_C zt)aG3uTh7n6Et<2In9F>NlT@zqLtGcXcuVrX|L#Xx)I%#9!{6gSJKPrN9dR61N3(c z4Tcqi$B1Vr8Jidf7-t!G7_XR2rWwr)$3XQ?}=hpK0&Z&W{| zep&sA23f;Q!%st`QJ}G3cbou<7-yIK2z4nfCCCtN2-XOGSWo##{8Q{ATurxr~;I`ytDs%xbip}RzP zziy}Qn4Z2~fSycmr`~zJ=lUFdFa1>gZThG6M+{g7vkW8#+YHVaJjFF}Z#*3@$J_By zLtVo_L#1JrVVB{Ak-5=4qt!-@Mh}c>#$4kh<88)m#-k<%CLtzEP3leVno>={htGUuD;o7bD)w_sX$S}eAxwzy?UvgBH(S?;#HZiQMoS*2K2 zT3xe7t(~nU*1N5{rxB;QPLocnp4Ml>u<^FZwyC!nu;thW+pe~4wtZn|Vi#w(#jeBd zlf9FDx_yoPJqHbk*$%56S{;6Kv~mM9!g3B(KJ}#RZ#@)!hR|78Dq|Iq-afF%KE1Brn_fm;Im z_u$xr8UFki1L{Ox>G0o)(&RAZ;=|I=wN2l97;cLaHH6leTB-XXa*h%dBOEvi`+x zi?=Txl?TadvyiL>SuF~-LZ;|cS}4~l2eM~nS7yJ>iOM;atDY;(?aZ^v+mJV$@1Ote z62cPUlD4IWOIIx&SmwQ~YB{nzae3Pc;}r!fhE@iwJh+OsDs9zItL;~pu715HdQEGA zUct(O!LkCy1<%NCg+}G`0PgpNm-?d@-hMgNe6^V+j6x$b<6@S<$+<4_1hi}Ti zncS4LsjI}fWY1>OX6feMEuLErma3QLmkw?X+1j)X-&VBk_4Y;EFPF_I+q;9dL%E~B zJh;4Nr^(LEJ3myURP{Rblsw%57T)g973R8o)DE9*xN#~;4_o$q%o z4K@u`jhx2fBXC4{U8Qn{*%*B$Ge=nny$HAYq{=vy|sI0 z_vss+H_qMky?OB#|JK!>IX&II^LlUh#rO5!7TtbwC;iULyV-Xq?ybB}ykGP{?LpZ? z-G|jbTmIbG@7#ZCz;~eY(cDM(28Dyq{*m>M4?_iynUBkc4TkHUI6gT!;y-fz>HMcd z&t%Ugo)`Y2{>!cx7B7DI)$7;J(U{Spm-3gBzioV_{p!H$8L!*M!p0uH$#^p{Ui4P` z?ZJ24cOCDe-w#jZd?0@)|7iKK^;6KN`;!@ylm7$*nDhK&GcDTy000JJOGiWi{{a60 z|De66lK=n!32;bRa{vGf6951U69E94oEQKA00(qQO+^Rb3LgwOCREZcC;$Kq%}GQ- zRCwC$U0aAGR~i1!sj9wBPxsF5>~50DMkU6LiFr^VUIHRMC@8*&;)~=VVnD?_NWd5I zO$1rRw-AK54+_2s3PE3jD2W(|Y)I5xHn_JWo5}3X?sWI`rRtpDhd$L^U0vOE>FSy8 zp8toUd#bB?s?YcR-+!r7Rf34Xc63eh5HJDQm;h`?)$FL1LWr5ac<-4f1rKljR(tH+ z%t>1??-Nl;U={)d02iSJf!FYRwkbG;-UpY#=UE7mD*+7f{vtz*6?o6!XCr|RkOH91 ztN&j6+od5wE(8bwFU_khq;(oXenk|^kBIX6Lnu`466Nyo!A_nI9EFblV&#n;Wb8hn zeFvt!_|ech(LlwIYQ*=5=oD*gd}YLT(gw7rp!Ic9?nUahFTm^ljglE~vSCL+|gMhub+%T5SX97&5qKpkmb^GXX+gZwYCAOjI|{*=HX3ytQ@T z_zs>K$dLi;jSuWZ@HI%OiD1V99-#^ZHL6At;KqWVl>l)h5E8KEkO-D-*4YqZxQ@Io z^m~`ux_RrD)NP#yaLW*(=ZA-BB*;X7P^`B_aqWB7=@0$f`S2%g*!C#sZW|yCa@{dN z0rWxj*9CwY0h2WJjcdbgQ`pQ^jLfMzmi7?H$ODz*#~rn;uMSSBPZmQAYB!+Xe*G0{ zH=ZD^-UQGzMDV7OATNZ*PBxw0aT19)PwV5~4^D z9LuD?bl~~2T>Xvnz$1O|eUA@NPdzQ9bw7Z003}m~i)kc~3Bk97Q~a{Eb@qp%cG9SlHAOG7NhrBpP;-|( zKh2o68$%MD`Dk5~*M9-vq#;2e4&yka{J3A0waurjt+S~B9?9wxnBLoAM6-~f*B*w0 zt+NjZr}(G|1(mo^Ad`5%ELVSI-}{MEexerXp;n>4Oow=4LPu^F)M+uAS;Il61(1d) zuS3>0ABT`z0M-B$1I@Y&3Ls=v)J}e16w3hgWa$s8LJF@RP@{2^rGFOldV@+zp8jA- z6w2QOPzxl4ktgV6jQm?dTHmtnymxKj<+dGxeTWoFr)DrZO$ITiP#~N#WTo~slLu4) zIFqoJvB_U`;~TPiEE;Ii5QSoNmoG_&ERe|X)U=#Jf!FQhQr$Qvr1h{-fWo9OAg3mX zLavEQ{ZoTAA@3g{L30U^SMgfYZButzG2mnGz>mga&v_U#L z!L#jrq>JnR9OHl>1l3k-(^clqU@MnF&yuSoTRf8|YdmN(|X%3jIt9p;n4B=qe~gh_vEvEAAT41Ipc9iIy#jbF_e&A~J)I)~GL&rNxdSW7!6$(_ z2Lep`63t4mWC>uT**sb+==?;0=jNFM=$Jf!<$dAgpK{9q(oXJRGAxu5tXt4?~^EL9pGLlaLFL4OSm7$tL%aJAk+rc{7 z%miTRUQY07o~__H)un8C=z4Nt=Mca-K*sEz?T8Q{2tL>RTm>W(j0AH5SXCAx4@kC^ z^5z2=_Wiv8YX$2I3rGF*sf35=9QV@XS`*I0@5Q$abz^)D+c}N7?!4ZK& z09OFHgaE!x%<6gn{6YZd3@g?Ln8_y01>m!c3sDBf(}aQIGLUU`RUi`qrcLkWWN`t^ zo<}E;6T9UjL4pZAe2bV>RDbhm0LoPXSP7195}4?wgM8L-H3^XBwxg3<0Za}q1KAGF zQk)Bj-!gE^QNFr&iFyEs-U?>fKYSA8Mu3F(ot?P5uN)EI!Bfr;xn00z-_iB{>>+?j zu_P(Jor3~QO%S~pLNHMdrwUl~S;2gYd5LlW_U7eF0fd#W0#L$x&$BIBD6n%NKnl5z ze8e300~R|^OkBg~Wu&ZW)3TpY?%!jC`|kUkOM zyx=fl&GmNi{HXYqtpp^4zpCiZ@$zuC#V-Mcv~rpckhDseFc)B?df;2bEO8PzuOyBu zi22CBb&w&z;z+Vs_~+9IqM3RFY>Su#Qcen>N1q`mSOJ#6D6IkrXuUJ(LBzARhIu~V z9L?@$|KxV}4e*pU1o%6>;{#3Y#^@GaFOUNiQpFv%d4gX6tU@2!?*0w{)t7AOv>|{% z`W3$d(9K(+_-{%)Ul}+NT#V4~6b&9WsN1?^2;gDDl|54lKw4de+j$QF&}jmy7gB)^ z=K+gGfbx1Dyygv1xBVJ`9st)6A+Z9GVT=dTe;FkIH{KrYE|DG~g|M9TJpj_Fo^;7J ztsJ)@svCfiP}^5QTD=IMYe=8~Q0=jElvDvU0FOGY-}`s})bC%5Pyuha&XU=bz%DR& zd3b+y143F5LO}0axd75T06K;QsT9Ch0YzF}fZO?(pZKZwE{|^+C<%qMQa^Hb5VzQ7 zO8%^kI|186d?=2X*=1uaj0U83ODZ0;Ep@4QqO&)j!~N{^Xa0-sM+E8$l)?AmxHo zhAWAMh-hTD194+ZZ3 zUXDJIqqUhsknSXpSg-TE!z^)s{RHIZ-Tk4z`3}^(Z~l(7dd(1^VR8V444uHB3Uonw zo7#=XNx4k`KzASR#g{;CJD(q76;sV-Wdr2#J7AsufC2wH-2XiPS8}_51aK3;EfWGJ zdVeed0xIAF*e9)CrsnPw)N40=CGg(50JU>9QVG(|1rTc+jA{~dO0c%>gFJp$0Q|qd zsQ34t25`eHx8uAYNOp@DUj;eP5x zqsWj$*bb;z0lND~4pSnEox>-bHOTrVM5R7xy?d8lg?IVYXQ|sd4`2ttwo!n6lf>&u z-VXpGD(;34Wbc_Lg;5I|Km|Y@LT<@&^(QD)zBsbIlz>x$D3l>=r{6f5;`xJ{Q3r2H z+uBW`gLZ6lBvBF?wL18_(tc0isU80P`y-DnxKHrCX{`&p*dNRCn(6WPOKoa5;J)$C zJ-vJV*QC`8#_QiV;5UuK>e^%HbQIZA5gNo!akQS%18 zYj1S*?)5)YxAh0(@wWo9-<;O@%S?a}2`oc`HA94&kk-fHl)fr#=d*B1C!z;s4g?5* zpUC6F-yPv~i3kuyf{`S4G65pNk0JnRP^S%QH=uW~YkhnBP3p9sC*?k8KyMh({fyr) z`Si5JFEarGBoKxK4uG-=3u^$X0M>-G?uL-}1GocH*3I?^ye^L&-UTgw@_iGeuaQ=l zOjoaMmS&*Sw~v0i*E9Rkw75SL0YW73iBK?0*(gH^K+zDyHrp&8_zRF58gKSb>Gn)) z?-&yJCwjbTlAk*PB8VUZNuq6lcMR}$Ko6M&=?UOhVah0i7kKq2dr(sFb0t6o5fC7Q zzlad45oS|1%7S>2oWI)Xa+qWA|Na1sR+P!bd2Y5F#*_^0BlFr{tuI& VIUE5v!FvDz002ovPDHLkV1mGwGtK}2 literal 0 HcmV?d00001 diff --git a/retroshare-gui/src/gui/icons/search_red_128.png b/retroshare-gui/src/gui/icons/search_red_128.png new file mode 100644 index 0000000000000000000000000000000000000000..f0fa88e22c2901aed324344b8402d10f45d7deff GIT binary patch literal 8931 zcmV<9A{^a`P)Oz@Z0f2-7z;ux~O9+4z06=<WDR*FRcSTFz- zW=q650N5=6FiBTtNC2?60Km==3$g$R3;-}uh=nNt1bYBr$Ri_o0EC$U6h`t_Jn<{8 z5a%iY0C<_QJh>z}MS)ugEpZ1|S1ukX&Pf+56gFW3VVXcL!g-k)GJ!M?;PcD?0HBc- z5#WRK{dmp}uFlRjj{U%*%WZ25jX z{P*?XzTzZ-GF^d31o+^>%=Ap99M6&ogks$0k4OBs3;+Bb(;~!4V!2o<6ys46agIcq zjPo+3B8fthDa9qy|77CdEc*jK-!%ZRYCZvbku9iQV*~a}ClFY4z~c7+0P?$U!PF=S z1Au6Q;m>#f??3%Vpd|o+W=WE9003S@Bra6Svp>fO002awfhw>;8}z{#EWidF!3EsG z3;bXU&9EIRU@z1_9W=mEXoiz;4lcq~xDGvV5BgyU zp1~-*fe8db$Osc*A=-!mVv1NJjtCc-h4>-CNCXm#Bp}I%6j35eku^v$Qi@a{RY)E3 zJ#qp$hg?Rwkvqr$GJ^buyhkyVfwECO)C{#lxu`c9ghrwZ&}4KmnvWKso6vH!8a<3Q zq36)6Xb;+tK10Vaz~~qUGsJ8#F2=(`u{bOVlVi)VBCHIn#u~6ztOL7=^<&SmcLWlF zMZgI*1b0FpVIDz9SWH+>*hr`#93(Um+6gxa1B6k+CnA%mOSC4s5&6UzVlpv@SV$}* z))J2sFA#f(L&P^E5{W}HC%KRUNwK6<(h|}}(r!{C=`5+6G)NjFlgZj-YqAG9lq?`C z$c5yc>d>VnA`E_*3F2Qp##d8RZb=H01_mm@+|Cqnc9PsG(F5HIG_C zt)aG3uTh7n6Et<2In9F>NlT@zqLtGcXcuVrX|L#Xx)I%#9!{6gSJKPrN9dR61N3(c z4Tcqi$B1Vr8Jidf7-t!G7_XR2rWwr)$3XQ?}=hpK0&Z&W{| zep&sA23f;Q!%st`QJ}G3cbou<7-yIK2z4nfCCCtN2-XOGSWo##{8Q{ATurxr~;I`ytDs%xbip}RzP zziy}Qn4Z2~fSycmr`~zJ=lUFdFa1>gZThG6M+{g7vkW8#+YHVaJjFF}Z#*3@$J_By zLtVo_L#1JrVVB{Ak-5=4qt!-@Mh}c>#$4kh<88)m#-k<%CLtzEP3leVno>={htGUuD;o7bD)w_sX$S}eAxwzy?UvgBH(S?;#HZiQMoS*2K2 zT3xe7t(~nU*1N5{rxB;QPLocnp4Ml>u<^FZwyC!nu;thW+pe~4wtZn|Vi#w(#jeBd zlf9FDx_yoPJqHbk*$%56S{;6Kv~mM9!g3B(KJ}#RZ#@)!hR|78Dq|Iq-afF%KE1Brn_fm;Im z_u$xr8UFki1L{Ox>G0o)(&RAZ;=|I=wN2l97;cLaHH6leTB-XXa*h%dBOEvi`+x zi?=Txl?TadvyiL>SuF~-LZ;|cS}4~l2eM~nS7yJ>iOM;atDY;(?aZ^v+mJV$@1Ote z62cPUlD4IWOIIx&SmwQ~YB{nzae3Pc;}r!fhE@iwJh+OsDs9zItL;~pu715HdQEGA zUct(O!LkCy1<%NCg+}G`0PgpNm-?d@-hMgNe6^V+j6x$b<6@S<$+<4_1hi}Ti zncS4LsjI}fWY1>OX6feMEuLErma3QLmkw?X+1j)X-&VBk_4Y;EFPF_I+q;9dL%E~B zJh;4Nr^(LEJ3myURP{Rblsw%57T)g973R8o)DE9*xN#~;4_o$q%o z4K@u`jhx2fBXC4{U8Qn{*%*B$Ge=nny$HAYq{=vy|sI0 z_vss+H_qMky?OB#|JK!>IX&II^LlUh#rO5!7TtbwC;iULyV-Xq?ybB}ykGP{?LpZ? z-G|jbTmIbG@7#ZCz;~eY(cDM(28Dyq{*m>M4?_iynUBkc4TkHUI6gT!;y-fz>HMcd z&t%Ugo)`Y2{>!cx7B7DI)$7;J(U{Spm-3gBzioV_{p!H$8L!*M!p0uH$#^p{Ui4P` z?ZJ24cOCDe-w#jZd?0@)|7iKK^;6KN`;!@ylm7$*nDhK&GcDTy000JJOGiWi{{a60 z|De66lK=n!32;bRa{vGf6951U69E94oEQKA00(qQO+^Rb3LgwRE$A(zV*mgc6-h)v zRCwC$U1^LP*M0xJV@M9q<(^!v4qMk+hh3>w96L?|H%HUf$d|N1zohx#q5;yP`A`IC z3$*!G1Ss6JKnoaYfy5tb^Z?xEK%E1rV#kSmBvvI^r!844?Mhnhp*_guHS^xNA23)hIWru--|v6E|9g)prOWeUnFDfbK02FO975Tg z0-UZBfpPmi4no%7Q)UVB?o>hMmcOA&YcB#=wuw-#m2_Q!1O;lI`P zKhD8m4sZJSwFXhw&^H_1{57rz7Ax=2c;XIyV1E7 z?Vv?0ve?8>g)GFaEAOg8_A5$?_W|T=BA9L@Xqf;tl22%a>hXWz2cGytHZ%cnZhE=}vWCQRQ-@dR9sRLP9Rwgc73qEI~ypy-I-UZ)tRH<-Ce^h(tkn*m_?{i0Ml! za%Jw1loW3RSOrk1n1n_oaQ3C&Us{!Xs>i>r9e&yZzasHY@LTqCH>yo}?{*FN{Z?nf zig~C)*6KS#!FC@>(bVX_63U(gkOH9FIUeejkMSgcL;5uuP5zDc$Wy;Z;zLkUKq_f{+)+UPx8!ew-$UUtklH zEdgBP)%$32b)k=FJ0vI<*3H4hciD{>ZHGh5N)V^r~U7%|Da5P2?!H3ISerV zgslO>c1Y;k2Ot0lq3ltb9Oh86v4h8XFsiE`_XlVPWHqHuLi#}){E+PjY{&^vj}UQ^ zL=%latp~r|OdtRl#XfKWnt`emhxDB`0kld|s8uI$f`oL-sdI__n~t9KTbD>+YXM4! zZ1CGAK%{BdM|pdoOXO+Xm;hwwwx))%@o z?n{;QVv8ie_Z$Y>bqFjm)bizohrrSquyh94|2TvYP_x${rZ2&mzX7_PeI8Rn`4sKe zHGpXbmH=v}k;D-A)Cf#ciT5OClVB#S7#6j@@-gr|M>{^dghi8JN1p-P`yq&nuR`2@f15giG5`WJyNTR7$B*uL z43VQB1=S*3+J`(E13&RB#QZc$XMYUjv)ji3Wd3Bkw`T`44WSdijmYs&Z8`Wgk1?_f z;b;B;Y{!A^A^b`~nMRNVkQ@B~x6gz45zzsJpZNm#&O^PyMIJ)<#IsnFs-foh7WuQOvSV(L89>j5HFfUrgXiQK?*?F)7Tn4OSuGj`e%?gu7E%N zEU1qRBR~8xnD=IZ<=Ok(1O&>^+9}s;*I{4YzA_CMr@jj{eZ4W@dIAW?fUpjDWeLkg zpi}@#IiP+%!qPmU zr=9i>@>f5Fm^$anA5ihZ-U8o;Q%tuK{Cap2dGE(O`JYyeJ7S+r2j)PECyU#R0tG3=pEdU)DcL#s&=6aGRy<_XaceZrK zG7AI{@1An+P_BWF@7*?jfWNbZ8K@Z`;V4)v;r^AE-m+dK1}!hYn~e~Qgp>jEcOd7d zJ$!+Ky&>K{#y6-h@PmFX4@XHA^H8^^txzvH+#?wi4%o}%h!5PuLTz}WyCcTbe|m=o z6;4<^<1_gXcTf3>sdue}Oe)j%dP5y)u@n%}p=Pc_xrE0g6seNsf%E}9zce=Bt^sCm z0O4rxaefdjIRcbRP>VC}W+0vEVtmbmBY;w3eFe{841kq_b^FeRyCCs&Z;DJ<2eb&} zoVy=DJV@RvX28D&5WzTsB&53*U#P+=U zggpvmySVNVA;h;9pj!ogb>jz*6~Ra>wJq=`VfV2KRW5Y@8GSg?TW$hW!F@&0o{j%E zL;~(fDwVz0^ASKxCLpL~VzMQ}TFtT<0k{Sd)q5U)nsTogmMil;Fa4b}0WQ}NLZPxt z?$;-JKZ!!qWA0tBI(HxC0XEfY$-o(fym#CEp+H>H8!M6lS19 z!kn>0*AI#iF8+vmdxW*zQSy_g+GXj%Gl(dz#mL{~d(7`Ru$C znZN*(L6LA6^45Fq55_~FJ0I>b>8D^1A9441mS%BfZW(&G%O;FdUj;o~DF}&1!nitp z%i8wLO^fY51QP9?fgv_H<}Lm2z6Q=XIP0DUAYi`N32dDJ0ce6~Bn$y~POD}FU`J2% z#Ml634D675&A%#SF?IPI68iQS3G_{X>W0g%o{xWGP)ZTkBe;3(J*fPu`?-1oZ1O13 z#kDwy6ks3vgy(t2nV%qUN+hC@`-cF&!1qiAY$Qh_7R8z&VP5#Tx9T0;4Z44_D;ywF zf zWd!`m&-eo0eCtQJbbSVtQlxr8{S(>)sbC+|%9F7uG|q5krG)aUFZr5G!O|IMk3R!4 z+@T30l!6Usz@L8BQ|$wQoVkiC-+lqOGlz6M3QBuq9z&psAfM~bdM1wQ?m;QR@PH*@ zm#$ugdHP5Gep@&K?dVfrkDdTYB!cNMPC>^fpndq0V24lm`(3L`Fkbi?@?`<@_8g2G zw;<*A+W)ZY%f%;RI`nV|g+dV*PMyS2Jpq2`BR=Euaj?O0$fdgwcc!407Oj%g7LX#7PU1$n3@Ie8 zy!t&%YGLsG{^!}#^cZM*3`$CsjGazlu zK2pUzj2HeIXRmD>)m)moW&NhdCed|k;A3*g=0+?k>jg9=gg>HaoMCJrfjf&UFoeSS zAO0tfd~_Mwu}`*0dB$z#Sx#xX?7BoQT%bZ6B5)e{hHE$JEUOfFa z9=UxDp-(>tn(FQ}ar4a2aP6P}9;-$FwGm6#tqG)=<43nt6Zl!>v?UGTckTHg+UP){ zCY5@5b`ewm@eP!J`3h7Qb|;f7^CkB|FU7x}1*^AxL1S|+2poLCv zxW!zH;UlF4G{I_F;KG})Ve;DlA@t;D!5(_7<5^)<$ig^#64%eYje;qy z1myTAC;{ZHxt2))0GVGq+}-G)9RdWM{c{q;ZQA)rDgn+o7FO27tSj@Y!1rImU{&~OS2F+FF{=W6)xXd*icBJ zltMV9p;R_Nh(c*(2r-~{NzlSr0B=`%x2i=$Av`oTh=r9Lma?_8ZI(&`OBc@r7te!J zg8gGdpd-6MQlp^h5fD8IXc4PJqy&s2lv##aU9fTm%d;rlxsIu9b03E@hS7lp;(8c! z%ULYv@*o7kkf4)g4nC7XyjOv*@e2sWNGgG3RL8Ea|riw+sPFZiw$;v|VU1&AcmO5C#8NJgY(Dr2n4EE>Q!%8Xk%j|1 z!IFR?bF90Lp??z~dy5E}bP{9f1XlAUtQAVgm&;IXhFY9)#Pty3(J-Q+kf-znM}lcv z6C4I(0g`}rdMu!mQ9_HRVIZbsAZ9s##j=5-VZty>luZFsN(i9* zY8hCS1iQyuzR%M2Y0RDpCSyogz^UMFtNQIof_R%Gm^*(tC>0RUS$-ymZj<$Jwvq(J zks-wQv_8vu@xANF-r2gTLTTO!9l0XpTx-RBX6MS^H82_D+n^!(VvyRjD88b^*q+Rqzr@C&4nKD8=L0Y%-9vkWO?XfO5?ZAlyf`O%eb= zS=WKRd#WnfBtXSD>OrKl8#{q2ARj>1?jcC}zNB9g_?bPNig#qI9M!51Kp^EpvyF&1 zn;H&w8=CD!f^?!e35HT}#Pv;TS9^srWt8$Z@Tyf4P`T)~QVIlCm26Ej%YbG-C<}p5 z6RMvQ_SHrPlF-8;Eai$Q8b(#^rxP*6wRmQ+?+5f)Bf3?ipmK{)rNU(ZWdMdv1m8}evKeDS$?Bwiv3RRCyQE|d zDF|!Pdlk~U2jzX_0tv^twcI|T5OdQ|QoIeIWRpMuP|4?>SAI2s1YoM-+P_yOXv+DS z23o*ee~;1jGyxCw!3#qA<7p7eKnQ_cxOoOjE&wRnBxp$kRJ4FlQk;QNJY8}8#N8Vk z&vb-@gtC^moUPiee%qAu$I{~f=P+llLKW9u0gwZ*=F|Yb2wYIVK8yy%0iCQCw#?^PEDrCO}U4yA5&Y{g;#! zmu&)MZ683OjZC0Z3zVSboGN6$q=aGZ`c%rpxcUy15zOvbgoRtGX6-kC4rai{_SoRh z!npX0SCvuv9)NoQmTeQzRQf#$;LrjFfV`68tjaBYMV0NXzsxesYiA%9rWg1$e0y! z%s?*BSu1Z1+6y#M3JBpZQDl>Ya1AOP1xon`4pVFW0pbxY#XwWTAkkEH$k&`Y5A(+P zS5#^3MF0x`=4=g+x1D&|O!@(UG_t$(53>5LuM%5ZZ~##NDG)kA_4wBiivDKJ`IG`$ z#M&mFYgXdOMe?hQQJap1Bi5E$(1YAFIpWI+ZS=PDceQ#S$F3bs*Y0P$_8RAFyP$*c zu+^7(%*yfGp|&byVZ8U&s$81=7bV3hTk7X+@N>4n%H(s;%SL2ti2!vZ&;UdLBmfK$ z%05mau`eSOJyN~SD-YlVty#y`fkFuJK9^JXjS}2C+|lXQ_p!#$Sh7!?dRMwe{B<>js(mmLChvXl2CRW zTI92YYaf9Y8EV`q9Uy=Md|wh*fA0oT=ZgT1NKoU%HYY$s@EZ|8NvL80s*r_Tnw4^8 z?tN8U`-Kw5NgMR64SL1nuY`Qk&GBoS01grmn*8A1nCqM%tP=}MqZQwNi+#{#J@Tlwa@zB|rlrz(Iz}LF$0-lfXat^_swWR7<`50^czL)DfW((0$N@ xAp+V3y(I$l+k?~kbzFS{^jn_*{r14N{|E5^Ret&BxJLj0002ovPDHLkV1o73toQ%` literal 0 HcmV?d00001 From 8fe85b9bdd868e4c07aba467fff0cbadc664d0d3 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Mon, 31 Oct 2016 23:24:35 +0100 Subject: [PATCH 22/52] improved ShareManager a little bit more --- retroshare-gui/src/gui/ShareManager.cpp | 59 +++++-------------- .../src/gui/common/GroupFlagsWidget.cpp | 16 ++--- 2 files changed, 22 insertions(+), 53 deletions(-) diff --git a/retroshare-gui/src/gui/ShareManager.cpp b/retroshare-gui/src/gui/ShareManager.cpp index 878a54e30..8ea8399a4 100644 --- a/retroshare-gui/src/gui/ShareManager.cpp +++ b/retroshare-gui/src/gui/ShareManager.cpp @@ -80,8 +80,8 @@ ShareManager::ShareManager() QHeaderView* header = ui.shareddirList->horizontalHeader(); QHeaderView_setSectionResizeModeColumn(header, COLUMN_PATH, QHeaderView::Stretch); - //header->setResizeMode(COLUMN_NETWORKWIDE, QHeaderView::Fixed); - //header->setResizeMode(COLUMN_BROWSABLE, QHeaderView::Fixed); +// header->setResizeMode(COLUMN_NETWORKWIDE, QHeaderView::ResizeToContents); +// header->setResizeMode(COLUMN_BROWSABLE, QHeaderView::ResizeToContents); header->setHighlightSections(false); @@ -109,7 +109,7 @@ void ShareManager::doubleClickedCell(int row,int column) } else if(column == COLUMN_GROUPS) { - std::list selected_groups = GroupSelectionDialog::selectGroups(std::list()) ; + std::list selected_groups = GroupSelectionDialog::selectGroups(mDirInfos[row].parent_groups) ; mDirInfos[row].parent_groups = selected_groups ; load(); @@ -194,13 +194,19 @@ void ShareManager::load() listWidget->setItem(row, COLUMN_GROUPS, new QTableWidgetItem()) ; listWidget->item(row,COLUMN_GROUPS)->setBackgroundColor(QColor(183,236,181)) ; - listWidget->item(row,COLUMN_GROUPS)->setText(getGroupString(mDirInfos[row].parent_groups)); connect(widget,SIGNAL(flagsChanged(FileStorageFlags)),this,SLOT(updateFlags())) ; listWidget->item(row,COLUMN_PATH)->setToolTip(tr("Double click to change shared directory path")) ; listWidget->item(row,COLUMN_GROUPS)->setToolTip(tr("Double click to select which groups of friends can see the files")) ; - listWidget->item(row,COLUMN_VIRTUALNAME)->setToolTip(tr("Double click to change the cirtual file name")) ; + listWidget->item(row,COLUMN_VIRTUALNAME)->setToolTip(tr("Double click to change the name that friends will see")) ; + + listWidget->item(row,COLUMN_GROUPS)->setText(getGroupString(mDirInfos[row].parent_groups)); + + QFont font = listWidget->item(row,COLUMN_GROUPS)->font(); + font.setBold(mDirInfos[row].shareflags & DIR_FLAGS_BROWSABLE) ; + listWidget->item(row,COLUMN_GROUPS)->setTextColor( (mDirInfos[row].shareflags & DIR_FLAGS_BROWSABLE)? (Qt::black):(Qt::lightGray)) ; + listWidget->item(row,COLUMN_GROUPS)->setFont(font); } listWidget->setColumnWidth(COLUMN_SHARE_FLAGS,132 * QFontMetricsF(font()).height()/14.0) ; @@ -251,22 +257,11 @@ void ShareManager::updateFlags() load() ; // update the GUI. } -// void ShareManager::updateFromWidget() -// { -// mDirInfos.clear(); -// -// for(uint32_t i=0;iitem(i,COLUMN_PATH)->text().toUtf8() ; -// sdi.virtualname = ui.shareddirList->item(i,COLUMN_VIRTUALNAME)->text().toUtf8() ; -// sdi.shareflags = dynamic_cast(ui.shareddirList->item(i,COLUMN_SHARE_FLAGS))->flags(); -// sdi.parent_groups = std::list();//ui.shareddirList->item(i,COLUMN_GROUPS)->text(); -// } -// } - QString ShareManager::getGroupString(const std::list& groups) { + if(groups.empty()) + return tr("[Everyone]") ; + int n = 0; QString group_string ; @@ -283,32 +278,6 @@ QString ShareManager::getGroupString(const std::list& groups) return group_string ; } -// void ShareManager::editShareDirectory() -// { -// /* id current dir */ -// int row = ui.shareddirList->currentRow(); -// QTableWidgetItem *item = ui.shareddirList->item(row, COLUMN_PATH); -// -// if (item) { -// std::string filename = item->text().toUtf8().constData(); -// -// std::list dirs; -// rsFiles->getSharedDirectories(dirs); -// -// std::list::const_iterator it; -// for (it = dirs.begin(); it != dirs.end(); ++it) { -// if (it->filename == filename) { -// /* file name found, show dialog */ -// ShareDialog sharedlg (it->filename, this); -// sharedlg.setWindowTitle(tr("Edit Shared Folder")); -// sharedlg.exec(); -// load(); -// break; -// } -// } -// } -// } - void ShareManager::removeShareDirectory() { /* id current dir */ diff --git a/retroshare-gui/src/gui/common/GroupFlagsWidget.cpp b/retroshare-gui/src/gui/common/GroupFlagsWidget.cpp index ac8969690..ad11c7c40 100644 --- a/retroshare-gui/src/gui/common/GroupFlagsWidget.cpp +++ b/retroshare-gui/src/gui/common/GroupFlagsWidget.cpp @@ -10,9 +10,9 @@ #define FLAGS_ANONYMOUS_DL_ON ":icons/anonymous_blue_128.png" #define FLAGS_ANONYMOUS_DL_OFF ":icons/blank_blue_128.png" -#define INDEX_BROWSABLE 0 -#define INDEX_ANON_SEARCH 1 -#define INDEX_ANON_DL 2 +#define INDEX_ANON_SEARCH 0 +#define INDEX_ANON_DL 1 +#define INDEX_BROWSABLE 2 /*QString GroupFlagsWidget::_tooltips_on[4] = { QObject::tr("Directory is visible to friends"), @@ -96,15 +96,15 @@ void GroupFlagsWidget::update_button_state(bool b,int button_id) { QString tip_on, tip_off; switch (button_id) { - case 0: - tip_on = tr("Directory is visible to friends"); - tip_off = tr("Directory is NOT visible to friends"); + case 2: + tip_on = tr("Directory is visible to some friends (see list at right)"); + tip_off = tr("Directory is NOT visible to any friend"); break; - case 1: + case 0: tip_on = tr("Directory can be searched anonymously"); tip_off = tr("Directory cannot be searched anonymously"); break; - case 2: + case 1: tip_on = tr("Files can be downloaded anonymously"); tip_off = tr("Files cannot be downloaded anonymously"); break; From 3430eece225c08ec770dee7cf73c0ac651e68dfb Mon Sep 17 00:00:00 2001 From: mr-alice Date: Tue, 1 Nov 2016 10:30:36 +0100 Subject: [PATCH 23/52] fixed display of share flags as a proper nice icon set --- retroshare-gui/src/gui/RemoteDirModel.cpp | 52 ++++++++++++++++++- retroshare-gui/src/gui/RemoteDirModel.h | 1 + retroshare-gui/src/gui/ShareManager.cpp | 15 +----- retroshare-gui/src/gui/SharedFilesDialog.cpp | 36 ++++++++++++- retroshare-gui/src/gui/icons.qrc | 1 + retroshare-gui/src/gui/icons/void_128.png | Bin 0 -> 5684 bytes 6 files changed, 89 insertions(+), 16 deletions(-) create mode 100644 retroshare-gui/src/gui/icons/void_128.png diff --git a/retroshare-gui/src/gui/RemoteDirModel.cpp b/retroshare-gui/src/gui/RemoteDirModel.cpp index 250eadfe4..25b8708d7 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.cpp +++ b/retroshare-gui/src/gui/RemoteDirModel.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include "RemoteDirModel.h" #include #include @@ -270,8 +271,55 @@ QString RetroshareDirModel::getAgeIndicatorString(const DirDetails &details) con return ret; } +const QIcon& RetroshareDirModel::getFlagsIcon(FileStorageFlags flags) +{ + static QIcon *static_icons[8] = {NULL}; + + int n=0; + if(flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD) n += 1 ; + if(flags & DIR_FLAGS_ANONYMOUS_SEARCH ) n += 2 ; + if(flags & DIR_FLAGS_BROWSABLE ) n += 4 ; + n-= 1; + + if(static_icons[n] == NULL) + { + QList icons ; + + if(flags & DIR_FLAGS_ANONYMOUS_SEARCH) + icons.push_back(QIcon(":icons/search_red_128.png")) ; + else + icons.push_back(QIcon(":icons/void_128.png")) ; + + if(flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD) + icons.push_back(QIcon(":icons/anonymous_blue_128.png")) ; + else + icons.push_back(QIcon(":icons/void_128.png")) ; + + if(flags & DIR_FLAGS_BROWSABLE) + icons.push_back(QIcon(":icons/browsable_green_128.png")) ; + else + icons.push_back(QIcon(":icons/void_128.png")) ; + + QPixmap pix ; + GxsIdDetails::GenerateCombinedPixmap(pix, icons, 128); + + static_icons[n] = new QIcon(pix); + + std::cerr << "Generated icon for flags " << std::hex << flags << std::endl; + } + return *static_icons[n] ; +} + QVariant RetroshareDirModel::decorationRole(const DirDetails& details,int coln) const { + if(coln == 3) + { + if(details.type == DIR_TYPE_PERSON) return QVariant() ; + + return getFlagsIcon(details.flags) ; + } + + if(coln > 0) return QVariant() ; @@ -351,7 +399,7 @@ QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const case 2: return misc::userFriendlyDuration(details.min_age); case 3: - return getFlagsString(details.flags); + return getFlagsIcon(details.flags);//getFlagsString(details.flags); // case 4: // { // QString ind(""); @@ -382,7 +430,7 @@ QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const case 2: return misc::userFriendlyDuration(details.min_age); case 3: - return getFlagsString(details.flags); + return QVariant();//getFlagsString(details.flags); case 4: return getGroupsString(details.parent_groups) ; diff --git a/retroshare-gui/src/gui/RemoteDirModel.h b/retroshare-gui/src/gui/RemoteDirModel.h index 72a3fad7c..de1180f2c 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.h +++ b/retroshare-gui/src/gui/RemoteDirModel.h @@ -97,6 +97,7 @@ class RetroshareDirModel : public QAbstractItemModel static QString getGroupsString(const std::list &) ; QString getAgeIndicatorString(const DirDetails &) const; // void getAgeIndicatorRec(const DirDetails &details, QString &ret) const; + static const QIcon& getFlagsIcon(FileStorageFlags flags) ; virtual QVariant displayRole(const DirDetails&,int) const = 0 ; virtual QVariant sortRole(const QModelIndex&,const DirDetails&,int) const =0; diff --git a/retroshare-gui/src/gui/ShareManager.cpp b/retroshare-gui/src/gui/ShareManager.cpp index 8ea8399a4..9d0fca3a7 100644 --- a/retroshare-gui/src/gui/ShareManager.cpp +++ b/retroshare-gui/src/gui/ShareManager.cpp @@ -62,7 +62,6 @@ ShareManager::ShareManager() ui.headerFrame->setHeaderText(tr("Share Manager")); isLoading = false; - load(); Settings->loadWidgetInformation(this); @@ -80,13 +79,12 @@ ShareManager::ShareManager() QHeaderView* header = ui.shareddirList->horizontalHeader(); QHeaderView_setSectionResizeModeColumn(header, COLUMN_PATH, QHeaderView::Stretch); -// header->setResizeMode(COLUMN_NETWORKWIDE, QHeaderView::ResizeToContents); -// header->setResizeMode(COLUMN_BROWSABLE, QHeaderView::ResizeToContents); - header->setHighlightSections(false); setAcceptDrops(true); setAttribute(Qt::WA_DeleteOnClose, true); + + reload(); } void ShareManager::doubleClickedCell(int row,int column) @@ -240,20 +238,11 @@ void ShareManager::showYourself() void ShareManager::updateFlags() { - if(isLoading) - return ; - - isLoading = true ; // stops GUI update. Otherwise each call to rsFiles->updateShareFlags() modifies the GUI that we count on to check - // what has changed => fail! - for(int row=0;rowrowCount();++row) { FileStorageFlags flags = (dynamic_cast(ui.shareddirList->cellWidget(row,COLUMN_SHARE_FLAGS)))->flags() ; - mDirInfos[row].shareflags = flags ; } - - isLoading = false ; // re-enable GUI load load() ; // update the GUI. } diff --git a/retroshare-gui/src/gui/SharedFilesDialog.cpp b/retroshare-gui/src/gui/SharedFilesDialog.cpp index 036dd96e2..ad22fb6f5 100644 --- a/retroshare-gui/src/gui/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/SharedFilesDialog.cpp @@ -25,8 +25,10 @@ #include #include #include +#include #include #include +#include #include "SharedFilesDialog.h" #include "settings/AddFileAssociationDialog.h" @@ -114,6 +116,36 @@ private: RetroshareDirModel *m_dirModel; }; +// This class allows to draw the item in the share flags column using an appropriate size + +class ShareFlagsItemDelegate: public QStyledItemDelegate +{ +public: + ShareFlagsItemDelegate() {} + + virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const + { + Q_ASSERT(index.isValid()); + + QStyleOptionViewItemV4 opt = option; + initStyleOption(&opt, index); + // disable default icon + opt.icon = QIcon(); + // draw default item + QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &opt, painter, 0); + + const QRect r = option.rect; + + // get pixmap + QIcon icon = qvariant_cast(index.data(Qt::DecorationRole)); + QPixmap pix = icon.pixmap(r.size()); + + // draw pixmap at center of item + const QPoint p = QPoint((r.width() - pix.width())/2, (r.height() - pix.height())/2); + painter->drawPixmap(r.topLeft() + p, pix); + } +}; + /** Constructor */ SharedFilesDialog::SharedFilesDialog(RetroshareDirModel *_tree_model,RetroshareDirModel *_flat_model,QWidget *parent) : RsAutoUpdatePage(1000,parent),model(NULL) @@ -220,7 +252,9 @@ LocalSharedFilesDialog::LocalSharedFilesDialog(QWidget *parent) editshareAct = new QAction(QIcon(IMAGE_EDITSHARE), tr("Edit Share Permissions"), this) ; connect(editshareAct, SIGNAL(triggered()), this, SLOT(editSharePermissions())) ; - ui.titleBarPixmap->setPixmap(QPixmap(IMAGE_MYFILES)) ; + ui.titleBarPixmap->setPixmap(QPixmap(IMAGE_MYFILES)) ; + + ui.dirTreeView->setItemDelegateForColumn(COLUMN_FRIEND,new ShareFlagsItemDelegate()) ; } RemoteSharedFilesDialog::RemoteSharedFilesDialog(QWidget *parent) diff --git a/retroshare-gui/src/gui/icons.qrc b/retroshare-gui/src/gui/icons.qrc index 473b474fe..38d6878fd 100644 --- a/retroshare-gui/src/gui/icons.qrc +++ b/retroshare-gui/src/gui/icons.qrc @@ -29,6 +29,7 @@ icons/avatar_128.png icons/avatar_grey_128.png icons/blank_red_128.png + icons/void_128.png icons/blank_green_128.png icons/blank_blue_128.png icons/browsable_green_128.png diff --git a/retroshare-gui/src/gui/icons/void_128.png b/retroshare-gui/src/gui/icons/void_128.png new file mode 100644 index 0000000000000000000000000000000000000000..4756cf8ccfd0146c19d5394e228c1472a646d7aa GIT binary patch literal 5684 zcmV-47R%|0P)Oz@Z0f2-7z;ux~O9+4z06=<WDR*FRcSTFz- zW=q650N5=6FiBTtNC2?60Km==3$g$R3;-}uh=nNt1bYBr$Ri_o0EC$U6h`t_Jn<{8 z5a%iY0C<_QJh>z}MS)ugEpZ1|S1ukX&Pf+56gFW3VVXcL!g-k)GJ!M?;PcD?0HBc- z5#WRK{dmp}uFlRjj{U%*%WZ25jX z{P*?XzTzZ-GF^d31o+^>%=Ap99M6&ogks$0k4OBs3;+Bb(;~!4V!2o<6ys46agIcq zjPo+3B8fthDa9qy|77CdEc*jK-!%ZRYCZvbku9iQV*~a}ClFY4z~c7+0P?$U!PF=S z1Au6Q;m>#f??3%Vpd|o+W=WE9003S@Bra6Svp>fO002awfhw>;8}z{#EWidF!3EsG z3;bXU&9EIRU@z1_9W=mEXoiz;4lcq~xDGvV5BgyU zp1~-*fe8db$Osc*A=-!mVv1NJjtCc-h4>-CNCXm#Bp}I%6j35eku^v$Qi@a{RY)E3 zJ#qp$hg?Rwkvqr$GJ^buyhkyVfwECO)C{#lxu`c9ghrwZ&}4KmnvWKso6vH!8a<3Q zq36)6Xb;+tK10Vaz~~qUGsJ8#F2=(`u{bOVlVi)VBCHIn#u~6ztOL7=^<&SmcLWlF zMZgI*1b0FpVIDz9SWH+>*hr`#93(Um+6gxa1B6k+CnA%mOSC4s5&6UzVlpv@SV$}* z))J2sFA#f(L&P^E5{W}HC%KRUNwK6<(h|}}(r!{C=`5+6G)NjFlgZj-YqAG9lq?`C z$c5yc>d>VnA`E_*3F2Qp##d8RZb=H01_mm@+|Cqnc9PsG(F5HIG_C zt)aG3uTh7n6Et<2In9F>NlT@zqLtGcXcuVrX|L#Xx)I%#9!{6gSJKPrN9dR61N3(c z4Tcqi$B1Vr8Jidf7-t!G7_XR2rWwr)$3XQ?}=hpK0&Z&W{| zep&sA23f;Q!%st`QJ}G3cbou<7-yIK2z4nfCCCtN2-XOGSWo##{8Q{ATurxr~;I`ytDs%xbip}RzP zziy}Qn4Z2~fSycmr`~zJ=lUFdFa1>gZThG6M+{g7vkW8#+YHVaJjFF}Z#*3@$J_By zLtVo_L#1JrVVB{Ak-5=4qt!-@Mh}c>#$4kh<88)m#-k<%CLtzEP3leVno>={htGUuD;o7bD)w_sX$S}eAxwzy?UvgBH(S?;#HZiQMoS*2K2 zT3xe7t(~nU*1N5{rxB;QPLocnp4Ml>u<^FZwyC!nu;thW+pe~4wtZn|Vi#w(#jeBd zlf9FDx_yoPJqHbk*$%56S{;6Kv~mM9!g3B(KJ}#RZ#@)!hR|78Dq|Iq-afF%KE1Brn_fm;Im z_u$xr8UFki1L{Ox>G0o)(&RAZ;=|I=wN2l97;cLaHH6leTB-XXa*h%dBOEvi`+x zi?=Txl?TadvyiL>SuF~-LZ;|cS}4~l2eM~nS7yJ>iOM;atDY;(?aZ^v+mJV$@1Ote z62cPUlD4IWOIIx&SmwQ~YB{nzae3Pc;}r!fhE@iwJh+OsDs9zItL;~pu715HdQEGA zUct(O!LkCy1<%NCg+}G`0PgpNm-?d@-hMgNe6^V+j6x$b<6@S<$+<4_1hi}Ti zncS4LsjI}fWY1>OX6feMEuLErma3QLmkw?X+1j)X-&VBk_4Y;EFPF_I+q;9dL%E~B zJh;4Nr^(LEJ3myURP{Rblsw%57T)g973R8o)DE9*xN#~;4_o$q%o z4K@u`jhx2fBXC4{U8Qn{*%*B$Ge=nny$HAYq{=vy|sI0 z_vss+H_qMky?OB#|JK!>IX&II^LlUh#rO5!7TtbwC;iULyV-Xq?ybB}ykGP{?LpZ? z-G|jbTmIbG@7#ZCz;~eY(cDM(28Dyq{*m>M4?_iynUBkc4TkHUI6gT!;y-fz>HMcd z&t%Ugo)`Y2{>!cx7B7DI)$7;J(U{Spm-3gBzioV_{p!H$8L!*M!p0uH$#^p{Ui4P` z?ZJ24cOCDe-w#jZd?0@)|7iKK^;6KN`;!@ylm7$*nDhK&GcDTy000JJOGiWi{{a60 z|De66lK=n!32;bRa{vGf6951U69E94oEQKA00(qQO+^Rb3jqln6_JN!ZvX%bW=TXr zRCwC$U0aXa#u+^`9O|-?*1PN5+A&bCn<9;yqG=PL54`|I3KZzS$U}Zr9`Y;Fq7OxZ z1Vw_PZqmBVL*ok^cZ1Z;dUv(DQR2+>K_We(C~01}u3096N6Ts9lGs7ZX`$t`!vB|AzW5SQbH}RL>tKwE`CjJnapzG`;g3^LvFC^$ z6L(IV|BFIJe$O<)ichf|<}7{9X2)>GptOdsCm3rFec8uE`53A}ZXx6rK$QF@-@=Z2 z3EykJhTF{p+^FAx)H3`aPkVFYedW(jH2jdPiJpW6Ma7_@Uc47GM#2wYn?eZ2nS`p@ zxx(?Yal!khc+4?U%LQ>ozi%Aj3>=&>xXc9u4@q~q00)O)E;wUwW@%ZC*TBKS7=yzc zNG=2#+IWq9+Tan#4!Fk2%itFn)|TOA-J82-+e{&MzUjm?O9^`;hSAsqq4# z)5)96x#@t^@yt_bJ)Q2y!^cZiz6wznTh{R`p^6r>^91LMj*os0pILh}bO`3cWiA@L zfjVzY$1sMj-^Jg1pQGz{W9Mm^2vQ5cBwsKW9nr?GcHhB4;|>^O&|1UOUTEEcOE<0B zv@X+?n&Jp7T5FAm!-w$HD4e7?>&i>?CJBJg<~&XS!Ep|A;4&9Yr->%t3iE`|&hFux z@i*2YFgZ`%2-*=l_|4vLanQIEp3EdaE#eZjue>L74J~=|q?-A1$LO7lrV=^U};H1SPiKq`mztDHMYez_G>pGm|Kho5X{BR+AXwr8(Qn7uHW9YX?$3PB=xdH_+ z)*c)PY*|zTi8;Wsx-yyzWbFh3z$in%pMaI&R>H>?-%2j=lLl-#Ehw!QYJbyZoAEoS z0MgX|X~q&P=2L4(NUKuNstSmM+3iac|IN#-i zi7QYB8cXmB5kQt0AI%-e-EXD{cvkWym4zFf11QVTohk&-1)FL>X&o*T%bf(8?tAVg z45JdHyr7yTpp^&6vbcj#9U+KyenBcR*FUeKNHr0v7XqvrL96P2ivODjzsMXQjhf=t z0<78-fUth7B?nN{AljH5fOZMH;CTQ~Yq5mtkYC7xkRr*aO5)`pO~;l(zy*h02%tpm z;tD_-mvyP;uLf8O$6iVZuvrU0US%`#0P7G?#`S*^LD}w|=NABxR6*hyvkn71=|q72 z>K_tIbu8aL2`p*p7hMfTGp|m=B4difYdV8 zrUQg^XZF0fMo^Z=s!<+r&iVj(K4jTi0O~B3hcul)x)yNZ!v*2odV$geu*xgYo`UDF z3Me|U3m+y)J%Cb0U?T)UQ*{pGdWxsNr@l3e_6)9o^+Q-cx-Yp3FrMtaDi@%#u9}J9 zOIa06jUg%n2^(4kq-q3FQ|JPhfoWYmiKQAMuzq4l9zs`bSU^HqFKD~?bD7wce0MPQ z0xBW|i-u6HPGGQNcv(xAdIM{!|7XP8c!ER$l(9h+38O+e0FhSR3V>OJ0IM8eqA2E9 zP6QCeY!H#AOpANO990qPA-}LHplH`moyEgv}?PffsW%km`T(0OYDGSOpZe zK}1>P(|W)S@f5ZLDVwhnsV{M-Pzn#58wLs!Kw9f3QLG;fyqMd=$@Nzcg1NA4s42Ah9>8{4SSA5z zt>GIBMV*wl7tp2P4Js9rO2EL{qgJ2S3y>En5AN(*z(5Z3dw_tbuHT(|-_zcUn8QV? zxI-upHC}_@0*o>AdNh2v-~}dn626z_k))L9)4 zbEaHbZ1JDSmZwG-t1$pztj2gS{BmK;*hmOn=BCaE8YF;1lE3dXZi6v~fA;U=%pw6? zDuAe)IFo0g7x;4U@7UyGpaye&e)CdfQX9GDw1~l+IA|U~Z~?6~{&sc`o{^vB@&JJs z7^*>70o?2Ubs@fJD2%l?=MB=tuBOu@7Bk{T{RZ~j%K(6nPd-{G*_RpiN&zf*0lybk z1S2)Vr>CF9Hglwwm?%H>Rli-aN6n!OxKg`<+sy+2z?0z<{HuT8+WM_MKu`^I{cdRC zJ$Z(YPd-9l_A@1Zad`kGgXwUy{tE6izY73(I{FHKc>X)|W#8KR69o`G$WtRcpB!VL z24Pb8$?2c*X!vlk#EYy2uz5_(<(V5JtVWBs@kZ;1xYf87lK=ao4{PJOP_-5XDh z(DkQBnkC17yr;NPyNR3iR{#VH669P`D3|arwS?3X4ceP6yZP z*KtYgpg!xle17&B{?h$)Y206B{Q$t?7Gy;CmU-`scNdkzTy#VmE#96h`yA$=$+ysQ zT4?YF9OlHvb_E4(EI2jC98HeGbqGn}g~#lOWq$wQ{Z;2#R<@dim}8bLv@ky-Iwx_* zL?7x9_Zu3#ftJ(4wsQ%BPwlnN>NxRF@TcQH;?O%>8S~@FH#xTwz%mg8O`ML?3CWI| z(CFlwt5w1cjUr>B=ZG$Ko|`P=TtPD`?Sw~vx7pPUgusmF@$s1NYyO61;t9qGV|*}n zSvx%-9+_Ha@5K#%zV0000 Date: Tue, 1 Nov 2016 10:46:29 +0100 Subject: [PATCH 24/52] fixed layout and names in ShareManager and SharedFilesDialog --- retroshare-gui/src/gui/RemoteDirModel.cpp | 29 +++++++++++------------ retroshare-gui/src/gui/RemoteDirModel.h | 2 +- retroshare-gui/src/gui/ShareManager.cpp | 2 ++ retroshare-gui/src/gui/ShareManager.ui | 6 ++--- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/retroshare-gui/src/gui/RemoteDirModel.cpp b/retroshare-gui/src/gui/RemoteDirModel.cpp index 25b8708d7..5aa09c62c 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.cpp +++ b/retroshare-gui/src/gui/RemoteDirModel.cpp @@ -223,9 +223,15 @@ QString RetroshareDirModel::getFlagsString(FileStorageFlags flags) return QString(str) ; } -QString RetroshareDirModel::getGroupsString(const std::list& group_ids) +QString RetroshareDirModel::getGroupsString(FileStorageFlags flags,const std::list& group_ids) { - QString groups_str ; + if(!(flags & DIR_FLAGS_BROWSABLE)) + return QString(); + + if(group_ids.empty()) + return tr("[Everyone]") ; + + QString groups_str = tr("Only "); RsGroupInfo group_info ; for(std::list::const_iterator it(group_ids.begin());it!=group_ids.end();) @@ -399,16 +405,9 @@ QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const case 2: return misc::userFriendlyDuration(details.min_age); case 3: - return getFlagsIcon(details.flags);//getFlagsString(details.flags); -// case 4: -// { -// QString ind(""); -// if (ageIndicator != IND_ALWAYS) -// ind = getAgeIndicatorString(details); -// return ind; -// } + return QVariant(); case 4: - return getGroupsString(details.parent_groups) ; + return getGroupsString(details.flags,details.parent_groups) ; default: return tr("FILE"); @@ -430,9 +429,9 @@ QVariant TreeStyle_RDM::displayRole(const DirDetails& details,int coln) const case 2: return misc::userFriendlyDuration(details.min_age); case 3: - return QVariant();//getFlagsString(details.flags); + return QVariant(); case 4: - return getGroupsString(details.parent_groups) ; + return getGroupsString(details.flags,details.parent_groups) ; default: return tr("DIR"); @@ -710,12 +709,12 @@ QVariant TreeStyle_RDM::headerData(int section, Qt::Orientation orientation, int if (RemoteMode) return tr("Friend"); else - return tr("Share Flags"); + return tr("Access"); case 4: if (RemoteMode) return tr("What's new"); else - return tr("Groups"); + return tr("Visibility"); } return QString("Column %1").arg(section); } diff --git a/retroshare-gui/src/gui/RemoteDirModel.h b/retroshare-gui/src/gui/RemoteDirModel.h index de1180f2c..bf7d8944c 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.h +++ b/retroshare-gui/src/gui/RemoteDirModel.h @@ -94,7 +94,7 @@ class RetroshareDirModel : public QAbstractItemModel void treeStyle(); void downloadDirectory(const DirDetails & details, int prefixLen); static QString getFlagsString(FileStorageFlags f) ; - static QString getGroupsString(const std::list &) ; + static QString getGroupsString(FileStorageFlags flags, const std::list &) ; QString getAgeIndicatorString(const DirDetails &) const; // void getAgeIndicatorRec(const DirDetails &details, QString &ret) const; static const QIcon& getFlagsIcon(FileStorageFlags flags) ; diff --git a/retroshare-gui/src/gui/ShareManager.cpp b/retroshare-gui/src/gui/ShareManager.cpp index 9d0fca3a7..7da676fee 100644 --- a/retroshare-gui/src/gui/ShareManager.cpp +++ b/retroshare-gui/src/gui/ShareManager.cpp @@ -160,6 +160,8 @@ void ShareManager::reload() std::list dirs ; rsFiles->getSharedDirectories(dirs) ; + mDirInfos.clear(); + for(std::list::const_iterator it(dirs.begin());it!=dirs.end();++it) mDirInfos.push_back(*it) ; diff --git a/retroshare-gui/src/gui/ShareManager.ui b/retroshare-gui/src/gui/ShareManager.ui index 63b1a980b..42d1bbd3a 100644 --- a/retroshare-gui/src/gui/ShareManager.ui +++ b/retroshare-gui/src/gui/ShareManager.ui @@ -6,7 +6,7 @@ 0 0 - 741 + 1210 334 @@ -111,7 +111,7 @@ - Share flags + Access @@ -119,7 +119,7 @@ - Groups + Visibility From c6df59a421ec54f06f0a23d4a73552028330cdc6 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Tue, 1 Nov 2016 11:11:28 +0100 Subject: [PATCH 25/52] fixed bug in duplication of virtual dir names --- retroshare-gui/src/gui/ShareManager.cpp | 23 +++++++++++++++++++++-- retroshare-gui/src/gui/ShareManager.h | 1 + 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/retroshare-gui/src/gui/ShareManager.cpp b/retroshare-gui/src/gui/ShareManager.cpp index 7da676fee..3f7d222dc 100644 --- a/retroshare-gui/src/gui/ShareManager.cpp +++ b/retroshare-gui/src/gui/ShareManager.cpp @@ -70,9 +70,8 @@ ShareManager::ShareManager() connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(cancel())); connect(ui.shareddirList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(shareddirListCostumPopupMenu(QPoint))); - connect(ui.shareddirList, SIGNAL(currentCellChanged(int,int,int,int)), this, SLOT(shareddirListCurrentCellChanged(int,int,int,int))); - connect(ui.shareddirList, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(doubleClickedCell(int,int))); + connect(ui.shareddirList, SIGNAL(cellChanged(int,int)), this, SLOT(handleCellChange(int,int))); connect(NotifyQt::getInstance(), SIGNAL(groupsChanged(int)), this, SLOT(reload())); @@ -87,6 +86,26 @@ ShareManager::ShareManager() reload(); } +void ShareManager::handleCellChange(int row,int column) +{ + if(isLoading) + return ; + + if(column == COLUMN_VIRTUALNAME) + { + // check if the thing already exists + + for(uint32_t i=0;iitem(i,COLUMN_VIRTUALNAME)->text().toUtf8()))) + { + ui.shareddirList->item(row,COLUMN_VIRTUALNAME)->setText(QString::fromUtf8(mDirInfos[row].virtualname.c_str())) ; + return ; + } + + mDirInfos[row].virtualname = std::string(ui.shareddirList->item(row,COLUMN_VIRTUALNAME)->text().toUtf8()) ; + } +} + void ShareManager::doubleClickedCell(int row,int column) { if(column == COLUMN_PATH) diff --git a/retroshare-gui/src/gui/ShareManager.h b/retroshare-gui/src/gui/ShareManager.h index c0b4a7474..04f3ef1e4 100644 --- a/retroshare-gui/src/gui/ShareManager.h +++ b/retroshare-gui/src/gui/ShareManager.h @@ -58,6 +58,7 @@ private slots: void shareddirListCostumPopupMenu( QPoint point ); void addShare(); void doubleClickedCell(int,int); + void handleCellChange(int row,int column); void showShareDialog(); //void editShareDirectory(); From ffdac640d854999688f9eaa470528a0ed81106af Mon Sep 17 00:00:00 2001 From: mr-alice Date: Tue, 1 Nov 2016 11:57:25 +0100 Subject: [PATCH 26/52] fixed swarming with encrypted end-to-end tunnels --- libretroshare/src/ft/ftserver.cc | 74 +++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 38efb452e..5e112cc43 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -546,42 +546,68 @@ void ftServer::removeVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualP bool ftServer::handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_id) { FileInfo info ; - bool res = FileDetails(hash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY, info); + RsFileHash real_hash ; + bool found = false ; - if(info.transfer_info_flags & RS_FILE_REQ_ENCRYPTED) + if(FileDetails(hash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY, info)) { + if(info.transfer_info_flags & RS_FILE_REQ_ENCRYPTED) + { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "handleTunnelRequest: openning encrypted FT tunnel for H(H(F))=" << hash << " and H(F)=" << info.hash << std::endl; + FTSERVER_DEBUG() << "handleTunnelRequest: openning encrypted FT tunnel for H(H(F))=" << hash << " and H(F)=" << info.hash << std::endl; #endif - RS_STACK_MUTEX(srvMutex) ; - mEncryptedHashes[hash] = info.hash; - } -#warning needs to tweak for swarming with encrypted FT - if( (!res) && FileDetails(hash,RS_FILE_HINTS_DOWNLOAD,info)) - { - // This file is currently being downloaded. Let's look if we already have a chunk or not. If not, no need to - // share the file! + RS_STACK_MUTEX(srvMutex) ; + mEncryptedHashes[hash] = info.hash; - FileChunksInfo info2 ; - if(rsFiles->FileDownloadChunksDetails(hash, info2)) - for(uint32_t i=0;i::const_iterator it = mEncryptedHashes.find(hash) ; + + if(it != mEncryptedHashes.end()) + real_hash = it->second ; + else + real_hash = hash ; + } + + if(FileDetails(real_hash,RS_FILE_HINTS_DOWNLOAD,info)) + { + // This file is currently being downloaded. Let's look if we already have a chunk or not. If not, no need to + // share the file! + + FileChunksInfo info2 ; + if(rsFiles->FileDownloadChunksDetails(hash, info2)) + for(uint32_t i=0;icomputePeerPermissionFlags(peer_id,info.storage_permission_flags,info.parent_groups)) ; + found = found && (RS_FILE_HINTS_NETWORK_WIDE & rsPeers->computePeerPermissionFlags(peer_id,info.storage_permission_flags,info.parent_groups)) ; - return res ; + return found ; } /***************************************************************/ From 6a3610e6cb71c07c89393d80beb2b7a621b83e3e Mon Sep 17 00:00:00 2001 From: mr-alice Date: Tue, 1 Nov 2016 14:13:43 +0100 Subject: [PATCH 27/52] disallow double tunnels (encrypted+clear) in Accepted mode, since it is not needed --- libretroshare/src/ft/ftcontroller.cc | 14 +++++++++----- libretroshare/src/ft/ftserver.cc | 9 +++++++-- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index fe6ada159..94d252ddf 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -979,16 +979,20 @@ bool ftController::FileRequest(const std::string& fname, const RsFileHash& hash if(alreadyHaveFile(hash, info)) return false ; + // the strategy for requesting encryption is the following: + // + // if policy is STRICT + // - disable clear, enforce encryption + // else + // - if not specified, use clear + // if(mDefaultEncryptionPolicy == RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT) { flags |= RS_FILE_REQ_ENCRYPTED ; flags &= ~RS_FILE_REQ_UNENCRYPTED ; } - else - { - flags |= RS_FILE_REQ_ENCRYPTED ; - flags |= RS_FILE_REQ_UNENCRYPTED ; - } + else if(!(flags & ( RS_FILE_REQ_ENCRYPTED | RS_FILE_REQ_UNENCRYPTED ))) + flags |= RS_FILE_REQ_UNENCRYPTED ; if(size == 0) // we treat this special case because { diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 5e112cc43..c1f826b7e 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -269,7 +269,6 @@ bool ftServer::activateTunnels(const RsFileHash& hash,TransferRequestFlags flags #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "Activating tunnels for hash " << hash << std::endl; #endif - if(flags & RS_FILE_REQ_ENCRYPTED) { #ifdef SERVER_DEBUG @@ -277,7 +276,7 @@ bool ftServer::activateTunnels(const RsFileHash& hash,TransferRequestFlags flags #endif mTurtleRouter->monitorTunnels(hash_of_hash,this,true) ; } - if(flags & RS_FILE_REQ_UNENCRYPTED) + if((flags & RS_FILE_REQ_UNENCRYPTED) && (mFtController->defaultEncryptionPolicy() != RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT)) { #ifdef SERVER_DEBUG FTSERVER_DEBUG() << " flags require no end-to-end encryption. Requesting hash " << hash << std::endl; @@ -599,6 +598,12 @@ bool ftServer::handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_i } } + if(mFtController->defaultEncryptionPolicy() == RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT && hash == real_hash) + { + std::cerr << "(WW) rejecting file transfer for hash " << hash << " because the hash is not encrypted and encryption policy requires it." << std::endl; + return false ; + } + #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "ftServer: performing local hash search for hash " << hash << std::endl; From 02f442a400f5b3ca3764e62a499ea8d9e6a137e4 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Tue, 1 Nov 2016 14:28:00 +0100 Subject: [PATCH 28/52] changed naming for files visibility --- retroshare-gui/src/gui/RemoteDirModel.cpp | 2 +- retroshare-gui/src/gui/ShareManager.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/retroshare-gui/src/gui/RemoteDirModel.cpp b/retroshare-gui/src/gui/RemoteDirModel.cpp index 5da0c1335..3d14f223d 100644 --- a/retroshare-gui/src/gui/RemoteDirModel.cpp +++ b/retroshare-gui/src/gui/RemoteDirModel.cpp @@ -229,7 +229,7 @@ QString RetroshareDirModel::getGroupsString(FileStorageFlags flags,const std::li return QString(); if(group_ids.empty()) - return tr("[Everyone]") ; + return tr("[All friend nodes]") ; QString groups_str = tr("Only "); RsGroupInfo group_info ; diff --git a/retroshare-gui/src/gui/ShareManager.cpp b/retroshare-gui/src/gui/ShareManager.cpp index 3f7d222dc..9201e4696 100644 --- a/retroshare-gui/src/gui/ShareManager.cpp +++ b/retroshare-gui/src/gui/ShareManager.cpp @@ -270,7 +270,7 @@ void ShareManager::updateFlags() QString ShareManager::getGroupString(const std::list& groups) { if(groups.empty()) - return tr("[Everyone]") ; + return tr("[All friend nodes]") ; int n = 0; QString group_string ; From d2118c5329fa725849e3c7f566e1faccbb74122b Mon Sep 17 00:00:00 2001 From: mr-alice Date: Wed, 2 Nov 2016 20:51:42 +0100 Subject: [PATCH 29/52] supressed deadlock in ftController due to calling ftServer from ftcontroller itself --- libretroshare/src/ft/ftcontroller.cc | 10 +- libretroshare/src/ft/ftserver.cc | 1002 +++++++++++++------------- libretroshare/src/ft/ftserver.h | 2 +- 3 files changed, 507 insertions(+), 507 deletions(-) diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index 4270da3d2..fdd7ab119 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -581,7 +581,7 @@ void ftController::locked_checkQueueElement(uint32_t pos) _queue[pos]->mState = ftFileControl::DOWNLOADING ; if(_queue[pos]->mFlags & RS_FILE_REQ_ANONYMOUS_ROUTING) - mFtServer->activateTunnels(_queue[pos]->mHash,_queue[pos]->mFlags,true); + mFtServer->activateTunnels(_queue[pos]->mHash,mDefaultEncryptionPolicy,_queue[pos]->mFlags,true); } if(pos >= _max_active_downloads && _queue[pos]->mState != ftFileControl::QUEUED && _queue[pos]->mState != ftFileControl::PAUSED) @@ -590,7 +590,7 @@ void ftController::locked_checkQueueElement(uint32_t pos) _queue[pos]->mCreator->closeFile() ; if(_queue[pos]->mFlags & RS_FILE_REQ_ANONYMOUS_ROUTING) - mFtServer->activateTunnels(_queue[pos]->mHash,_queue[pos]->mFlags,false); + mFtServer->activateTunnels(_queue[pos]->mHash,mDefaultEncryptionPolicy,_queue[pos]->mFlags,false); } } @@ -834,7 +834,7 @@ bool ftController::completeFile(const RsFileHash& hash) mDownloads.erase(it); if(flags & RS_FILE_REQ_ANONYMOUS_ROUTING) - mFtServer->activateTunnels(hash_to_suppress,flags,false); + mFtServer->activateTunnels(hash_to_suppress,mDefaultEncryptionPolicy,flags,false); } // UNLOCK: RS_STACK_MUTEX(ctrlMutex); @@ -1188,7 +1188,7 @@ bool ftController::FileRequest(const std::string& fname, const RsFileHash& hash // We check that flags are consistent. if(flags & RS_FILE_REQ_ANONYMOUS_ROUTING) - mFtServer->activateTunnels(hash,flags,true); + mFtServer->activateTunnels(hash,mDefaultEncryptionPolicy,flags,true); bool assume_availability = false; @@ -1289,7 +1289,7 @@ bool ftController::setChunkStrategy(const RsFileHash& hash,FileChunksInfo::Chunk bool ftController::FileCancel(const RsFileHash& hash) { - mFtServer->activateTunnels(hash,TransferRequestFlags(0),false); + mFtServer->activateTunnels(hash,mDefaultEncryptionPolicy,TransferRequestFlags(0),false); #ifdef CONTROL_DEBUG std::cerr << "ftController::FileCancel" << std::endl; diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index c1f826b7e..b24b034cc 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -64,15 +64,15 @@ const int ftserverzone = 29539; static const time_t FILE_TRANSFER_LOW_PRIORITY_TASKS_PERIOD = 5 ; // low priority tasks handling every 5 seconds - /* Setup */ + /* Setup */ ftServer::ftServer(p3PeerMgr *pm, p3ServiceControl *sc) : p3Service(), mPeerMgr(pm), mServiceCtrl(sc), mFileDatabase(NULL), - mFtController(NULL), mFtExtra(NULL), - mFtDataplex(NULL), mFtSearch(NULL), srvMutex("ftServer") + mFtController(NULL), mFtExtra(NULL), + mFtDataplex(NULL), mFtSearch(NULL), srvMutex("ftServer") { - addSerialType(new RsFileTransferSerialiser()) ; + addSerialType(new RsFileTransferSerialiser()) ; } const std::string FILE_TRANSFER_APP_NAME = "ft"; @@ -83,79 +83,79 @@ const uint16_t FILE_TRANSFER_MIN_MINOR_VERSION = 0; RsServiceInfo ftServer::getServiceInfo() { - return RsServiceInfo(RS_SERVICE_TYPE_FILE_TRANSFER, - FILE_TRANSFER_APP_NAME, - FILE_TRANSFER_APP_MAJOR_VERSION, - FILE_TRANSFER_APP_MINOR_VERSION, - FILE_TRANSFER_MIN_MAJOR_VERSION, - FILE_TRANSFER_MIN_MINOR_VERSION); + return RsServiceInfo(RS_SERVICE_TYPE_FILE_TRANSFER, + FILE_TRANSFER_APP_NAME, + FILE_TRANSFER_APP_MAJOR_VERSION, + FILE_TRANSFER_APP_MINOR_VERSION, + FILE_TRANSFER_MIN_MAJOR_VERSION, + FILE_TRANSFER_MIN_MINOR_VERSION); } void ftServer::setConfigDirectory(std::string path) { - mConfigPath = path; + mConfigPath = path; - /* Must update the sub classes ... if they exist - * TODO. - */ + /* Must update the sub classes ... if they exist + * TODO. + */ - std::string basecachedir = mConfigPath + "/cache"; - std::string localcachedir = mConfigPath + "/cache/local"; - std::string remotecachedir = mConfigPath + "/cache/remote"; + std::string basecachedir = mConfigPath + "/cache"; + std::string localcachedir = mConfigPath + "/cache/local"; + std::string remotecachedir = mConfigPath + "/cache/remote"; - RsDirUtil::checkCreateDirectory(basecachedir) ; - RsDirUtil::checkCreateDirectory(localcachedir) ; - RsDirUtil::checkCreateDirectory(remotecachedir) ; + RsDirUtil::checkCreateDirectory(basecachedir) ; + RsDirUtil::checkCreateDirectory(localcachedir) ; + RsDirUtil::checkCreateDirectory(remotecachedir) ; } - /* Control Interface */ + /* Control Interface */ - /* add Config Items (Extra, Controller) */ + /* add Config Items (Extra, Controller) */ void ftServer::addConfigComponents(p3ConfigMgr */*mgr*/) { - /* NOT SURE ABOUT THIS ONE */ + /* NOT SURE ABOUT THIS ONE */ } const RsPeerId& ftServer::OwnId() { - static RsPeerId null_id ; + static RsPeerId null_id ; - if (mServiceCtrl) - return mServiceCtrl->getOwnId(); - else - return null_id ; + if (mServiceCtrl) + return mServiceCtrl->getOwnId(); + else + return null_id ; } - /* Final Setup (once everything is assigned) */ + /* Final Setup (once everything is assigned) */ void ftServer::SetupFtServer() { - /* setup FiStore/Monitor */ - std::string localcachedir = mConfigPath + "/cache/local"; - std::string remotecachedir = mConfigPath + "/cache/remote"; - RsPeerId ownId = mServiceCtrl->getOwnId(); + /* setup FiStore/Monitor */ + std::string localcachedir = mConfigPath + "/cache/local"; + std::string remotecachedir = mConfigPath + "/cache/remote"; + RsPeerId ownId = mServiceCtrl->getOwnId(); - /* search/extras List */ - mFtExtra = new ftExtraList(); - mFtSearch = new ftFileSearch(); + /* search/extras List */ + mFtExtra = new ftExtraList(); + mFtSearch = new ftFileSearch(); - /* Transport */ - mFtDataplex = new ftDataMultiplex(ownId, this, mFtSearch); + /* Transport */ + mFtDataplex = new ftDataMultiplex(ownId, this, mFtSearch); - /* make Controller */ + /* make Controller */ mFtController = new ftController(mFtDataplex, mServiceCtrl, getServiceInfo().mServiceType); - mFtController -> setFtSearchNExtra(mFtSearch, mFtExtra); - std::string tmppath = "."; - mFtController->setPartialsDirectory(tmppath); - mFtController->setDownloadDirectory(tmppath); + mFtController -> setFtSearchNExtra(mFtSearch, mFtExtra); + std::string tmppath = "."; + mFtController->setPartialsDirectory(tmppath); + mFtController->setDownloadDirectory(tmppath); - /* complete search setup */ - mFtSearch->addSearchMode(mFtExtra, RS_FILE_HINTS_EXTRA); + /* complete search setup */ + mFtSearch->addSearchMode(mFtExtra, RS_FILE_HINTS_EXTRA); - mServiceCtrl->registerServiceMonitor(mFtController, getServiceInfo().mServiceType); + mServiceCtrl->registerServiceMonitor(mFtController, getServiceInfo().mServiceType); - return; + return; } void ftServer::connectToFileDatabase(p3FileDatabase *fdb) @@ -165,54 +165,54 @@ void ftServer::connectToFileDatabase(p3FileDatabase *fdb) } void ftServer::connectToTurtleRouter(p3turtle *fts) { - mTurtleRouter = fts ; + mTurtleRouter = fts ; - mFtController->setTurtleRouter(fts) ; - mFtController->setFtServer(this) ; + mFtController->setTurtleRouter(fts) ; + mFtController->setFtServer(this) ; - mTurtleRouter->registerTunnelService(this) ; + mTurtleRouter->registerTunnelService(this) ; } void ftServer::StartupThreads() { - /* start up order - important for dependencies */ + /* start up order - important for dependencies */ - /* self contained threads */ - /* startup ExtraList Thread */ - mFtExtra->start("ft extra lst"); + /* self contained threads */ + /* startup ExtraList Thread */ + mFtExtra->start("ft extra lst"); - /* startup Monitor Thread */ - /* startup the FileMonitor (after cache load) */ - /* start it up */ + /* startup Monitor Thread */ + /* startup the FileMonitor (after cache load) */ + /* start it up */ mFileDatabase->startThreads(); - /* Controller thread */ - mFtController->start("ft ctrl"); + /* Controller thread */ + mFtController->start("ft ctrl"); - /* Dataplex */ - mFtDataplex->start("ft dataplex"); + /* Dataplex */ + mFtDataplex->start("ft dataplex"); } void ftServer::StopThreads() { - /* stop Dataplex */ - mFtDataplex->join(); + /* stop Dataplex */ + mFtDataplex->join(); - /* stop Controller thread */ - mFtController->join(); + /* stop Controller thread */ + mFtController->join(); - /* self contained threads */ - /* stop ExtraList Thread */ - mFtExtra->join(); + /* self contained threads */ + /* stop ExtraList Thread */ + mFtExtra->join(); - delete (mFtDataplex); - mFtDataplex = NULL; + delete (mFtDataplex); + mFtDataplex = NULL; - delete (mFtController); - mFtController = NULL; + delete (mFtController); + mFtController = NULL; - delete (mFtExtra); - mFtExtra = NULL; + delete (mFtExtra); + mFtExtra = NULL; /* stop Monitor Thread */ mFileDatabase->stopThreads(); @@ -230,9 +230,9 @@ void ftServer::StopThreads() bool ftServer::ResumeTransfers() { - mFtController->activate(); + mFtController->activate(); - return true; + return true; } bool ftServer::getFileData(const RsFileHash& hash, uint64_t offset, uint32_t& requested_size,uint8_t *data) @@ -251,13 +251,13 @@ bool ftServer::FileRequest(const std::string& fname, const RsFileHash& hash, uin FTSERVER_DEBUG() << "Requesting " << fname << std::endl ; #endif - if(!mFtController->FileRequest(fname, hash, size, dest, flags, srcIds)) - return false ; + if(!mFtController->FileRequest(fname, hash, size, dest, flags, srcIds)) + return false ; - return true ; + return true ; } -bool ftServer::activateTunnels(const RsFileHash& hash,TransferRequestFlags flags,bool onoff) +bool ftServer::activateTunnels(const RsFileHash& hash,uint32_t encryption_policy,TransferRequestFlags flags,bool onoff) { RsFileHash hash_of_hash ; @@ -276,7 +276,7 @@ bool ftServer::activateTunnels(const RsFileHash& hash,TransferRequestFlags flags #endif mTurtleRouter->monitorTunnels(hash_of_hash,this,true) ; } - if((flags & RS_FILE_REQ_UNENCRYPTED) && (mFtController->defaultEncryptionPolicy() != RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT)) + if((flags & RS_FILE_REQ_UNENCRYPTED) && (encryption_policy != RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT)) { #ifdef SERVER_DEBUG FTSERVER_DEBUG() << " flags require no end-to-end encryption. Requesting hash " << hash << std::endl; @@ -294,27 +294,27 @@ bool ftServer::activateTunnels(const RsFileHash& hash,TransferRequestFlags flags bool ftServer::setDestinationName(const RsFileHash& hash,const std::string& name) { - return mFtController->setDestinationName(hash,name); + return mFtController->setDestinationName(hash,name); } bool ftServer::setDestinationDirectory(const RsFileHash& hash,const std::string& directory) { - return mFtController->setDestinationDirectory(hash,directory); + return mFtController->setDestinationDirectory(hash,directory); } bool ftServer::setChunkStrategy(const RsFileHash& hash,FileChunksInfo::ChunkStrategy s) { - return mFtController->setChunkStrategy(hash,s); + return mFtController->setChunkStrategy(hash,s); } uint32_t ftServer::freeDiskSpaceLimit()const { - return mFtController->freeDiskSpaceLimit() ; + return mFtController->freeDiskSpaceLimit() ; } void ftServer::setFreeDiskSpaceLimit(uint32_t s) { - mFtController->setFreeDiskSpaceLimit(s) ; + mFtController->setFreeDiskSpaceLimit(s) ; } -void ftServer::setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy s) +void ftServer::setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy s) { - mFtController->setDefaultChunkStrategy(s) ; + mFtController->setDefaultChunkStrategy(s) ; } uint32_t ftServer::defaultEncryptionPolicy() { @@ -324,55 +324,55 @@ void ftServer::setDefaultEncryptionPolicy(uint32_t s) { mFtController->setDefaultEncryptionPolicy(s) ; } -FileChunksInfo::ChunkStrategy ftServer::defaultChunkStrategy() +FileChunksInfo::ChunkStrategy ftServer::defaultChunkStrategy() { - return mFtController->defaultChunkStrategy() ; + return mFtController->defaultChunkStrategy() ; } bool ftServer::FileCancel(const RsFileHash& hash) { - // Remove from both queue and ftController, by default. - // - mFtController->FileCancel(hash); + // Remove from both queue and ftController, by default. + // + mFtController->FileCancel(hash); - return true ; + return true ; } bool ftServer::FileControl(const RsFileHash& hash, uint32_t flags) { - return mFtController->FileControl(hash, flags); + return mFtController->FileControl(hash, flags); } bool ftServer::FileClearCompleted() { - return mFtController->FileClearCompleted(); + return mFtController->FileClearCompleted(); } void ftServer::setQueueSize(uint32_t s) { - mFtController->setQueueSize(s) ; + mFtController->setQueueSize(s) ; } uint32_t ftServer::getQueueSize() { - return mFtController->getQueueSize() ; + return mFtController->getQueueSize() ; } - /* Control of Downloads Priority. */ + /* Control of Downloads Priority. */ bool ftServer::changeQueuePosition(const RsFileHash& hash, QueueMove mv) { - mFtController->moveInQueue(hash,mv) ; - return true ; + mFtController->moveInQueue(hash,mv) ; + return true ; } bool ftServer::changeDownloadSpeed(const RsFileHash& hash, int speed) { - mFtController->setPriority(hash, (DwlSpeed)speed); - return true ; + mFtController->setPriority(hash, (DwlSpeed)speed); + return true ; } bool ftServer::getDownloadSpeed(const RsFileHash& hash, int & speed) { - DwlSpeed _speed; - int ret = mFtController->getPriority(hash, _speed); - if (ret) - speed = _speed; + DwlSpeed _speed; + int ret = mFtController->getPriority(hash, _speed); + if (ret) + speed = _speed; - return ret; + return ret; } bool ftServer::clearDownload(const RsFileHash& /*hash*/) { @@ -381,7 +381,7 @@ bool ftServer::clearDownload(const RsFileHash& /*hash*/) bool ftServer::FileDownloadChunksDetails(const RsFileHash& hash,FileChunksInfo& info) { - return mFtController->getFileDownloadChunksDetails(hash,info); + return mFtController->getFileDownloadChunksDetails(hash,info); } void ftServer::requestDirUpdate(void *ref) @@ -392,22 +392,22 @@ void ftServer::requestDirUpdate(void *ref) /* Directory Handling */ void ftServer::setDownloadDirectory(std::string path) { - mFtController->setDownloadDirectory(path); + mFtController->setDownloadDirectory(path); } std::string ftServer::getDownloadDirectory() { - return mFtController->getDownloadDirectory(); + return mFtController->getDownloadDirectory(); } void ftServer::setPartialsDirectory(std::string path) { - mFtController->setPartialsDirectory(path); + mFtController->setPartialsDirectory(path); } std::string ftServer::getPartialsDirectory() { - return mFtController->getPartialsDirectory(); + return mFtController->getPartialsDirectory(); } /***************************************************************/ @@ -426,73 +426,73 @@ void ftServer::FileDownloads(std::list &hashs) bool ftServer::FileUploadChunksDetails(const RsFileHash& hash,const RsPeerId& peer_id,CompressedChunkMap& cmap) { - return mFtDataplex->getClientChunkMap(hash,peer_id,cmap); + return mFtDataplex->getClientChunkMap(hash,peer_id,cmap); } bool ftServer::FileUploads(std::list &hashs) { - return mFtDataplex->FileUploads(hashs); + return mFtDataplex->FileUploads(hashs); } bool ftServer::FileDetails(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) { - if (hintflags & RS_FILE_HINTS_DOWNLOAD) - if(mFtController->FileDetails(hash, info)) - return true ; + if (hintflags & RS_FILE_HINTS_DOWNLOAD) + if(mFtController->FileDetails(hash, info)) + return true ; - if(hintflags & RS_FILE_HINTS_UPLOAD) - if(mFtDataplex->FileDetails(hash, hintflags, info)) - { - // We also check if the file is a DL as well. In such a case we use - // the DL as the file name, to replace the hash. If the file is a cache - // file, we skip the call to fileDetails() for efficiency reasons. - // - FileInfo info2 ; + if(hintflags & RS_FILE_HINTS_UPLOAD) + if(mFtDataplex->FileDetails(hash, hintflags, info)) + { + // We also check if the file is a DL as well. In such a case we use + // the DL as the file name, to replace the hash. If the file is a cache + // file, we skip the call to fileDetails() for efficiency reasons. + // + FileInfo info2 ; if(mFtController->FileDetails(hash, info2)) - info.fname = info2.fname ; + info.fname = info2.fname ; - return true ; - } + return true ; + } - if(hintflags & ~(RS_FILE_HINTS_UPLOAD | RS_FILE_HINTS_DOWNLOAD)) - if(mFtSearch->search(hash, hintflags, info)) - return true ; + if(hintflags & ~(RS_FILE_HINTS_UPLOAD | RS_FILE_HINTS_DOWNLOAD)) + if(mFtSearch->search(hash, hintflags, info)) + return true ; - return false; + return false; } RsTurtleGenericTunnelItem *ftServer::deserialiseItem(void *data,uint32_t size) const { - uint32_t rstype = getRsItemId(data); + uint32_t rstype = getRsItemId(data); #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "p3turtle: deserialising packet: " << std::endl ; #endif - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_TURTLE != getRsItemService(rstype))) - { + if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_TURTLE != getRsItemService(rstype))) + { FTSERVER_ERROR() << " Wrong type !!" << std::endl ; - return NULL; /* wrong type */ - } + return NULL; /* wrong type */ + } try { - switch(getRsItemSubType(rstype)) - { - case RS_TURTLE_SUBTYPE_FILE_REQUEST : return new RsTurtleFileRequestItem(data,size) ; - case RS_TURTLE_SUBTYPE_FILE_DATA : return new RsTurtleFileDataItem(data,size) ; - case RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST : return new RsTurtleFileMapRequestItem(data,size) ; - case RS_TURTLE_SUBTYPE_FILE_MAP : return new RsTurtleFileMapItem(data,size) ; - case RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST : return new RsTurtleChunkCrcRequestItem(data,size) ; - case RS_TURTLE_SUBTYPE_CHUNK_CRC : return new RsTurtleChunkCrcItem(data,size) ; + switch(getRsItemSubType(rstype)) + { + case RS_TURTLE_SUBTYPE_FILE_REQUEST : return new RsTurtleFileRequestItem(data,size) ; + case RS_TURTLE_SUBTYPE_FILE_DATA : return new RsTurtleFileDataItem(data,size) ; + case RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST : return new RsTurtleFileMapRequestItem(data,size) ; + case RS_TURTLE_SUBTYPE_FILE_MAP : return new RsTurtleFileMapItem(data,size) ; + case RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST : return new RsTurtleChunkCrcRequestItem(data,size) ; + case RS_TURTLE_SUBTYPE_CHUNK_CRC : return new RsTurtleChunkCrcItem(data,size) ; - default: - return NULL ; - } + default: + return NULL ; + } } catch(std::exception& e) { FTSERVER_ERROR() << "(EE) deserialisation error in " << __PRETTY_FUNCTION__ << ": " << e.what() << std::endl; - + return NULL ; } } @@ -530,7 +530,7 @@ void ftServer::addVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeer } } -void ftServer::removeVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id) +void ftServer::removeVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id) { RsFileHash real_hash ; if(findRealHash(hash,real_hash)) @@ -608,7 +608,7 @@ bool ftServer::handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_i FTSERVER_DEBUG() << "ftServer: performing local hash search for hash " << hash << std::endl; if(found) - { + { FTSERVER_DEBUG() << "Found hash: " << std::endl; FTSERVER_DEBUG() << " hash = " << real_hash << std::endl; FTSERVER_DEBUG() << " peer = " << peer_id << std::endl; @@ -618,12 +618,12 @@ bool ftServer::handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_i FTSERVER_DEBUG() << (*it) << ", " ; FTSERVER_DEBUG() << std::endl; FTSERVER_DEBUG() << " clear = " << rsPeers->computePeerPermissionFlags(peer_id,info.storage_permission_flags,info.parent_groups) << std::endl; - } + } #endif - // The call to computeHashPeerClearance() return a combination of RS_FILE_HINTS_NETWORK_WIDE and RS_FILE_HINTS_BROWSABLE - // This is an additional computation cost, but the way it's written here, it's only called when res is true. - // + // The call to computeHashPeerClearance() return a combination of RS_FILE_HINTS_NETWORK_WIDE and RS_FILE_HINTS_BROWSABLE + // This is an additional computation cost, but the way it's written here, it's only called when res is true. + // found = found && (RS_FILE_HINTS_NETWORK_WIDE & rsPeers->computePeerPermissionFlags(peer_id,info.storage_permission_flags,info.parent_groups)) ; return found ; @@ -635,27 +635,27 @@ bool ftServer::handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_i bool ftServer::ExtraFileAdd(std::string fname, const RsFileHash& hash, uint64_t size, uint32_t period, TransferRequestFlags flags) { - return mFtExtra->addExtraFile(fname, hash, size, period, flags); + return mFtExtra->addExtraFile(fname, hash, size, period, flags); } bool ftServer::ExtraFileRemove(const RsFileHash& hash, TransferRequestFlags flags) { - return mFtExtra->removeExtraFile(hash, flags); + return mFtExtra->removeExtraFile(hash, flags); } bool ftServer::ExtraFileHash(std::string localpath, uint32_t period, TransferRequestFlags flags) { - return mFtExtra->hashExtraFile(localpath, period, flags); + return mFtExtra->hashExtraFile(localpath, period, flags); } bool ftServer::ExtraFileStatus(std::string localpath, FileInfo &info) { - return mFtExtra->hashExtraFileDone(localpath, info); + return mFtExtra->hashExtraFileDone(localpath, info); } bool ftServer::ExtraFileMove(std::string fname, const RsFileHash& hash, uint64_t size, std::string destpath) { - return mFtExtra->moveExtraFile(fname, hash, size, destpath); + return mFtExtra->moveExtraFile(fname, hash, size, destpath); } /***************************************************************/ @@ -701,9 +701,9 @@ int ftServer::SearchBoolExp(RsRegularExpression::Expression * exp, std::listSearchBoolExp(exp,results,flags,peer_id) ; } - /***************************************************************/ - /*************** Local Shared Dir Interface ********************/ - /***************************************************************/ + /***************************************************************/ + /*************** Local Shared Dir Interface ********************/ + /***************************************************************/ bool ftServer::ConvertSharedFilePath(std::string path, std::string &fullpath) { @@ -717,7 +717,7 @@ void ftServer::updateSinceGroupPermissionsChanged() void ftServer::ForceDirectoryCheck() { mFileDatabase->forceDirectoryCheck(); - return; + return; } bool ftServer::InDirectoryCheck() @@ -728,48 +728,48 @@ bool ftServer::InDirectoryCheck() bool ftServer::getSharedDirectories(std::list &dirs) { mFileDatabase->getSharedDirectories(dirs); - return true; + return true; } bool ftServer::setSharedDirectories(const std::list& dirs) { mFileDatabase->setSharedDirectories(dirs); - return true; + return true; } bool ftServer::addSharedDirectory(const SharedDirInfo& dir) { - SharedDirInfo _dir = dir; - _dir.filename = RsDirUtil::convertPathToUnix(_dir.filename); + SharedDirInfo _dir = dir; + _dir.filename = RsDirUtil::convertPathToUnix(_dir.filename); - std::list dirList; + std::list dirList; mFileDatabase->getSharedDirectories(dirList); - // check that the directory is not already in the list. - for(std::list::const_iterator it(dirList.begin());it!=dirList.end();++it) - if((*it).filename == _dir.filename) - return false ; + // check that the directory is not already in the list. + for(std::list::const_iterator it(dirList.begin());it!=dirList.end();++it) + if((*it).filename == _dir.filename) + return false ; - // ok then, add the shared directory. - dirList.push_back(_dir); + // ok then, add the shared directory. + dirList.push_back(_dir); mFileDatabase->setSharedDirectories(dirList); - return true; + return true; } bool ftServer::updateShareFlags(const SharedDirInfo& info) { mFileDatabase->updateShareFlags(info); - return true ; + return true ; } bool ftServer::removeSharedDirectory(std::string dir) { - dir = RsDirUtil::convertPathToUnix(dir); + dir = RsDirUtil::convertPathToUnix(dir); - std::list dirList; - std::list::iterator it; + std::list dirList; + std::list::iterator it; #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "ftServer::removeSharedDirectory(" << dir << ")" << std::endl; @@ -778,27 +778,27 @@ bool ftServer::removeSharedDirectory(std::string dir) mFileDatabase->getSharedDirectories(dirList); #ifdef SERVER_DEBUG - for(it = dirList.begin(); it != dirList.end(); ++it) + for(it = dirList.begin(); it != dirList.end(); ++it) FTSERVER_DEBUG() << " existing: " << (*it).filename << std::endl; #endif - for(it = dirList.begin();it!=dirList.end() && (*it).filename != dir;++it) ; + for(it = dirList.begin();it!=dirList.end() && (*it).filename != dir;++it) ; - if(it == dirList.end()) - { + if(it == dirList.end()) + { FTSERVER_ERROR() << "(EE) ftServer::removeSharedDirectory(): Cannot Find Directory... Fail" << std::endl; - return false; - } + return false; + } #ifdef SERVER_DEBUG FTSERVER_DEBUG() << " Updating Directories" << std::endl; #endif - dirList.erase(it); + dirList.erase(it); mFileDatabase->setSharedDirectories(dirList); - return true; + return true; } bool ftServer::watchEnabled() { return mFileDatabase->watchEnabled() ; } int ftServer::watchPeriod() const { return mFileDatabase->watchPeriod()/60 ; } @@ -808,30 +808,30 @@ void ftServer::setWatchPeriod(int minutes) { mFileDatabase->set bool ftServer::getShareDownloadDirectory() { - std::list dirList; + std::list dirList; mFileDatabase->getSharedDirectories(dirList); - std::string dir = mFtController->getDownloadDirectory(); + std::string dir = mFtController->getDownloadDirectory(); - // check if the download directory is in the list. - for (std::list::const_iterator it(dirList.begin()); it != dirList.end(); ++it) - if ((*it).filename == dir) - return true; + // check if the download directory is in the list. + for (std::list::const_iterator it(dirList.begin()); it != dirList.end(); ++it) + if ((*it).filename == dir) + return true; - return false; + return false; } bool ftServer::shareDownloadDirectory(bool share) { if (share) { - /* Share */ - SharedDirInfo inf ; - inf.filename = mFtController->getDownloadDirectory(); + /* Share */ + SharedDirInfo inf ; + inf.filename = mFtController->getDownloadDirectory(); inf.shareflags = DIR_FLAGS_ANONYMOUS_DOWNLOAD ; - return addSharedDirectory(inf); - } + return addSharedDirectory(inf); + } else { /* Unshare */ @@ -840,18 +840,18 @@ bool ftServer::shareDownloadDirectory(bool share) } } - /***************************************************************/ - /****************** End of RsFiles Interface *******************/ - /***************************************************************/ + /***************************************************************/ + /****************** End of RsFiles Interface *******************/ + /***************************************************************/ //bool ftServer::loadConfigMap(std::map &/*configMap*/) //{ // return true; //} - /***************************************************************/ - /********************** Data Flow **********************/ - /***************************************************************/ + /***************************************************************/ + /********************** Data Flow **********************/ + /***************************************************************/ bool ftServer::sendTurtleItem(const RsPeerId& peerId,const RsFileHash& hash,RsTurtleGenericTunnelItem *item) { @@ -888,42 +888,42 @@ bool ftServer::sendTurtleItem(const RsPeerId& peerId,const RsFileHash& hash,RsTu return true ; } - /* Client Send */ + /* Client Send */ bool ftServer::sendDataRequest(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize) { #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "ftServer::sendDataRequest() to peer " << peerId << " for hash " << hash << ", offset=" << offset << ", chunk size="<< chunksize << std::endl; #endif - if(mTurtleRouter->isTurtlePeer(peerId)) - { - RsTurtleFileRequestItem *item = new RsTurtleFileRequestItem ; + if(mTurtleRouter->isTurtlePeer(peerId)) + { + RsTurtleFileRequestItem *item = new RsTurtleFileRequestItem ; - item->chunk_offset = offset ; - item->chunk_size = chunksize ; + item->chunk_offset = offset ; + item->chunk_size = chunksize ; sendTurtleItem(peerId,hash,item) ; - } - else + } + else { - /* create a packet */ - /* push to networking part */ - RsFileTransferDataRequestItem *rfi = new RsFileTransferDataRequestItem(); + /* create a packet */ + /* push to networking part */ + RsFileTransferDataRequestItem *rfi = new RsFileTransferDataRequestItem(); - /* id */ - rfi->PeerId(peerId); + /* id */ + rfi->PeerId(peerId); - /* file info */ - rfi->file.filesize = size; - rfi->file.hash = hash; /* ftr->hash; */ + /* file info */ + rfi->file.filesize = size; + rfi->file.hash = hash; /* ftr->hash; */ - /* offsets */ - rfi->fileoffset = offset; /* ftr->offset; */ - rfi->chunksize = chunksize; /* ftr->chunk; */ + /* offsets */ + rfi->fileoffset = offset; /* ftr->offset; */ + rfi->chunksize = chunksize; /* ftr->chunk; */ - sendItem(rfi); - } + sendItem(rfi); + } - return true; + return true; } bool ftServer::sendChunkMapRequest(const RsPeerId& peerId,const RsFileHash& hash,bool is_client) @@ -931,28 +931,28 @@ bool ftServer::sendChunkMapRequest(const RsPeerId& peerId,const RsFileHash& hash #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "ftServer::sendChunkMapRequest() to peer " << peerId << " for hash " << hash << std::endl; #endif - if(mTurtleRouter->isTurtlePeer(peerId)) - { - RsTurtleFileMapRequestItem *item = new RsTurtleFileMapRequestItem ; + if(mTurtleRouter->isTurtlePeer(peerId)) + { + RsTurtleFileMapRequestItem *item = new RsTurtleFileMapRequestItem ; sendTurtleItem(peerId,hash,item) ; } - else - { - /* create a packet */ - /* push to networking part */ - RsFileTransferChunkMapRequestItem *rfi = new RsFileTransferChunkMapRequestItem(); + else + { + /* create a packet */ + /* push to networking part */ + RsFileTransferChunkMapRequestItem *rfi = new RsFileTransferChunkMapRequestItem(); - /* id */ - rfi->PeerId(peerId); + /* id */ + rfi->PeerId(peerId); - /* file info */ - rfi->hash = hash; /* ftr->hash; */ - rfi->is_client = is_client ; + /* file info */ + rfi->hash = hash; /* ftr->hash; */ + rfi->is_client = is_client ; - sendItem(rfi); - } + sendItem(rfi); + } - return true ; + return true ; } bool ftServer::sendChunkMap(const RsPeerId& peerId,const RsFileHash& hash,const CompressedChunkMap& map,bool is_client) @@ -960,30 +960,30 @@ bool ftServer::sendChunkMap(const RsPeerId& peerId,const RsFileHash& hash,const #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "ftServer::sendChunkMap() to peer " << peerId << " for hash " << hash << std::endl; #endif - if(mTurtleRouter->isTurtlePeer(peerId)) - { - RsTurtleFileMapItem *item = new RsTurtleFileMapItem ; - item->compressed_map = map ; + if(mTurtleRouter->isTurtlePeer(peerId)) + { + RsTurtleFileMapItem *item = new RsTurtleFileMapItem ; + item->compressed_map = map ; sendTurtleItem(peerId,hash,item) ; } - else - { - /* create a packet */ - /* push to networking part */ - RsFileTransferChunkMapItem *rfi = new RsFileTransferChunkMapItem(); + else + { + /* create a packet */ + /* push to networking part */ + RsFileTransferChunkMapItem *rfi = new RsFileTransferChunkMapItem(); - /* id */ - rfi->PeerId(peerId); + /* id */ + rfi->PeerId(peerId); - /* file info */ - rfi->hash = hash; /* ftr->hash; */ - rfi->is_client = is_client; /* ftr->hash; */ - rfi->compressed_map = map; /* ftr->hash; */ + /* file info */ + rfi->hash = hash; /* ftr->hash; */ + rfi->is_client = is_client; /* ftr->hash; */ + rfi->compressed_map = map; /* ftr->hash; */ - sendItem(rfi); - } + sendItem(rfi); + } - return true ; + return true ; } bool ftServer::sendSingleChunkCRCRequest(const RsPeerId& peerId,const RsFileHash& hash,uint32_t chunk_number) @@ -991,30 +991,30 @@ bool ftServer::sendSingleChunkCRCRequest(const RsPeerId& peerId,const RsFileHash #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "ftServer::sendSingleCRCRequest() to peer " << peerId << " for hash " << hash << ", chunk number=" << chunk_number << std::endl; #endif - if(mTurtleRouter->isTurtlePeer(peerId)) - { - RsTurtleChunkCrcRequestItem *item = new RsTurtleChunkCrcRequestItem; - item->chunk_number = chunk_number ; + if(mTurtleRouter->isTurtlePeer(peerId)) + { + RsTurtleChunkCrcRequestItem *item = new RsTurtleChunkCrcRequestItem; + item->chunk_number = chunk_number ; sendTurtleItem(peerId,hash,item) ; } - else - { - /* create a packet */ - /* push to networking part */ - RsFileTransferSingleChunkCrcRequestItem *rfi = new RsFileTransferSingleChunkCrcRequestItem(); + else + { + /* create a packet */ + /* push to networking part */ + RsFileTransferSingleChunkCrcRequestItem *rfi = new RsFileTransferSingleChunkCrcRequestItem(); - /* id */ - rfi->PeerId(peerId); + /* id */ + rfi->PeerId(peerId); - /* file info */ - rfi->hash = hash; /* ftr->hash; */ - rfi->chunk_number = chunk_number ; + /* file info */ + rfi->hash = hash; /* ftr->hash; */ + rfi->chunk_number = chunk_number ; - sendItem(rfi); - } + sendItem(rfi); + } - return true ; + return true ; } bool ftServer::sendSingleChunkCRC(const RsPeerId& peerId,const RsFileHash& hash,uint32_t chunk_number,const Sha1CheckSum& crc) @@ -1022,116 +1022,116 @@ bool ftServer::sendSingleChunkCRC(const RsPeerId& peerId,const RsFileHash& hash, #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "ftServer::sendSingleCRC() to peer " << peerId << " for hash " << hash << ", chunk number=" << chunk_number << std::endl; #endif - if(mTurtleRouter->isTurtlePeer(peerId)) - { - RsTurtleChunkCrcItem *item = new RsTurtleChunkCrcItem; - item->chunk_number = chunk_number ; - item->check_sum = crc ; + if(mTurtleRouter->isTurtlePeer(peerId)) + { + RsTurtleChunkCrcItem *item = new RsTurtleChunkCrcItem; + item->chunk_number = chunk_number ; + item->check_sum = crc ; sendTurtleItem(peerId,hash,item) ; } - else - { - /* create a packet */ - /* push to networking part */ - RsFileTransferSingleChunkCrcItem *rfi = new RsFileTransferSingleChunkCrcItem(); + else + { + /* create a packet */ + /* push to networking part */ + RsFileTransferSingleChunkCrcItem *rfi = new RsFileTransferSingleChunkCrcItem(); - /* id */ - rfi->PeerId(peerId); + /* id */ + rfi->PeerId(peerId); - /* file info */ - rfi->hash = hash; /* ftr->hash; */ - rfi->check_sum = crc; - rfi->chunk_number = chunk_number; + /* file info */ + rfi->hash = hash; /* ftr->hash; */ + rfi->check_sum = crc; + rfi->chunk_number = chunk_number; - sendItem(rfi); - } + sendItem(rfi); + } - return true ; + return true ; } - /* Server Send */ + /* Server Send */ bool ftServer::sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t baseoffset, uint32_t chunksize, void *data) { - /* create a packet */ - /* push to networking part */ - uint32_t tosend = chunksize; - uint64_t offset = 0; - uint32_t chunk; + /* create a packet */ + /* push to networking part */ + uint32_t tosend = chunksize; + uint64_t offset = 0; + uint32_t chunk; #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "ftServer::sendData() to " << peerId << ", hash: " << hash << " offset: " << baseoffset << " chunk: " << chunksize << " data: " << data << std::endl; #endif - while(tosend > 0) - { - //static const uint32_t MAX_FT_CHUNK = 32 * 1024; /* 32K */ - //static const uint32_t MAX_FT_CHUNK = 16 * 1024; /* 16K */ - // - static const uint32_t MAX_FT_CHUNK = 8 * 1024; /* 16K */ + while(tosend > 0) + { + //static const uint32_t MAX_FT_CHUNK = 32 * 1024; /* 32K */ + //static const uint32_t MAX_FT_CHUNK = 16 * 1024; /* 16K */ + // + static const uint32_t MAX_FT_CHUNK = 8 * 1024; /* 16K */ - /* workout size */ - chunk = MAX_FT_CHUNK; - if (chunk > tosend) - { - chunk = tosend; - } + /* workout size */ + chunk = MAX_FT_CHUNK; + if (chunk > tosend) + { + chunk = tosend; + } - /******** New Serialiser Type *******/ + /******** New Serialiser Type *******/ - if(mTurtleRouter->isTurtlePeer(peerId)) - { - RsTurtleFileDataItem *item = new RsTurtleFileDataItem ; + if(mTurtleRouter->isTurtlePeer(peerId)) + { + RsTurtleFileDataItem *item = new RsTurtleFileDataItem ; - item->chunk_offset = offset+baseoffset ; - item->chunk_size = chunk; - item->chunk_data = rs_malloc(chunk) ; + item->chunk_offset = offset+baseoffset ; + item->chunk_size = chunk; + item->chunk_data = rs_malloc(chunk) ; - if(item->chunk_data == NULL) - { - delete item; - return false; - } - memcpy(item->chunk_data,&(((uint8_t *) data)[offset]),chunk) ; + if(item->chunk_data == NULL) + { + delete item; + return false; + } + memcpy(item->chunk_data,&(((uint8_t *) data)[offset]),chunk) ; sendTurtleItem(peerId,hash,item) ; } - else - { - RsFileTransferDataItem *rfd = new RsFileTransferDataItem(); + else + { + RsFileTransferDataItem *rfd = new RsFileTransferDataItem(); - /* set id */ - rfd->PeerId(peerId); + /* set id */ + rfd->PeerId(peerId); - /* file info */ - rfd->fd.file.filesize = size; - rfd->fd.file.hash = hash; - rfd->fd.file.name = ""; /* blank other data */ - rfd->fd.file.path = ""; - rfd->fd.file.pop = 0; - rfd->fd.file.age = 0; + /* file info */ + rfd->fd.file.filesize = size; + rfd->fd.file.hash = hash; + rfd->fd.file.name = ""; /* blank other data */ + rfd->fd.file.path = ""; + rfd->fd.file.pop = 0; + rfd->fd.file.age = 0; - rfd->fd.file_offset = baseoffset + offset; + rfd->fd.file_offset = baseoffset + offset; - /* file data */ - rfd->fd.binData.setBinData( &(((uint8_t *) data)[offset]), chunk); + /* file data */ + rfd->fd.binData.setBinData( &(((uint8_t *) data)[offset]), chunk); - sendItem(rfd); + sendItem(rfd); - /* print the data pointer */ + /* print the data pointer */ #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "ftServer::sendData() Packet: " << " offset: " << rfd->fd.file_offset << " chunk: " << chunk << " len: " << rfd->fd.binData.bin_len << " data: " << rfd->fd.binData.bin_data << std::endl; #endif - } + } - offset += chunk; - tosend -= chunk; - } + offset += chunk; + tosend -= chunk; + } - /* clean up data */ - free(data); + /* clean up data */ + free(data); - return true; + return true; } // Encrypts the given item using aead-chacha20-poly1305 @@ -1371,9 +1371,9 @@ bool ftServer::findRealHash(const RsFileHash& hash, RsFileHash& real_hash) // Dont delete the item. The client (p3turtle) is doing it after calling this. // void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i, - const RsFileHash& hash, - const RsPeerId& virtual_peer_id, - RsTurtleGenericTunnelItem::Direction direction) + const RsFileHash& hash, + const RsPeerId& virtual_peer_id, + RsTurtleGenericTunnelItem::Direction direction) { if(i->PacketSubType() == RS_TURTLE_SUBTYPE_GENERIC_DATA) { @@ -1402,88 +1402,88 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i, return ; } - switch(i->PacketSubType()) - { - case RS_TURTLE_SUBTYPE_FILE_REQUEST: - { - RsTurtleFileRequestItem *item = dynamic_cast(i) ; - if (item) - { + switch(i->PacketSubType()) + { + case RS_TURTLE_SUBTYPE_FILE_REQUEST: + { + RsTurtleFileRequestItem *item = dynamic_cast(i) ; + if (item) + { #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received file data request for " << hash << " from peer " << virtual_peer_id << std::endl; #endif - getMultiplexer()->recvDataRequest(virtual_peer_id,hash,0,item->chunk_offset,item->chunk_size) ; - } - } - break ; + getMultiplexer()->recvDataRequest(virtual_peer_id,hash,0,item->chunk_offset,item->chunk_size) ; + } + } + break ; - case RS_TURTLE_SUBTYPE_FILE_DATA : - { - RsTurtleFileDataItem *item = dynamic_cast(i) ; - if (item) - { + case RS_TURTLE_SUBTYPE_FILE_DATA : + { + RsTurtleFileDataItem *item = dynamic_cast(i) ; + if (item) + { #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received file data for " << hash << " from peer " << virtual_peer_id << std::endl; #endif - getMultiplexer()->recvData(virtual_peer_id,hash,0,item->chunk_offset,item->chunk_size,item->chunk_data) ; + getMultiplexer()->recvData(virtual_peer_id,hash,0,item->chunk_offset,item->chunk_size,item->chunk_data) ; - item->chunk_data = NULL ; // this prevents deletion in the destructor of RsFileDataItem, because data will be deleted - // down _ft_server->getMultiplexer()->recvData()...in ftTransferModule::recvFileData - } - } - break ; + item->chunk_data = NULL ; // this prevents deletion in the destructor of RsFileDataItem, because data will be deleted + // down _ft_server->getMultiplexer()->recvData()...in ftTransferModule::recvFileData + } + } + break ; - case RS_TURTLE_SUBTYPE_FILE_MAP : - { - RsTurtleFileMapItem *item = dynamic_cast(i) ; - if (item) - { + case RS_TURTLE_SUBTYPE_FILE_MAP : + { + RsTurtleFileMapItem *item = dynamic_cast(i) ; + if (item) + { #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received chunk map for hash " << hash << " from peer " << virtual_peer_id << std::endl; #endif - getMultiplexer()->recvChunkMap(virtual_peer_id,hash,item->compressed_map,direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ; - } - } - break ; + getMultiplexer()->recvChunkMap(virtual_peer_id,hash,item->compressed_map,direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ; + } + } + break ; - case RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST: - { - //RsTurtleFileMapRequestItem *item = dynamic_cast(i) ; + case RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST: + { + //RsTurtleFileMapRequestItem *item = dynamic_cast(i) ; #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received chunkmap request for hash " << hash << " from peer " << virtual_peer_id << std::endl; #endif - getMultiplexer()->recvChunkMapRequest(virtual_peer_id,hash,direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ; - } - break ; + getMultiplexer()->recvChunkMapRequest(virtual_peer_id,hash,direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ; + } + break ; - case RS_TURTLE_SUBTYPE_CHUNK_CRC : - { - RsTurtleChunkCrcItem *item = dynamic_cast(i) ; - if (item) - { + case RS_TURTLE_SUBTYPE_CHUNK_CRC : + { + RsTurtleChunkCrcItem *item = dynamic_cast(i) ; + if (item) + { #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received single chunk CRC for hash " << hash << " from peer " << virtual_peer_id << std::endl; #endif - getMultiplexer()->recvSingleChunkCRC(virtual_peer_id,hash,item->chunk_number,item->check_sum) ; - } - } - break ; + getMultiplexer()->recvSingleChunkCRC(virtual_peer_id,hash,item->chunk_number,item->check_sum) ; + } + } + break ; - case RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST: - { - RsTurtleChunkCrcRequestItem *item = dynamic_cast(i) ; - if (item) - { + case RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST: + { + RsTurtleChunkCrcRequestItem *item = dynamic_cast(i) ; + if (item) + { #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received single chunk CRC request for hash " << hash << " from peer " << virtual_peer_id << std::endl; #endif - getMultiplexer()->recvSingleChunkCRCRequest(virtual_peer_id,hash,item->chunk_number) ; - } - } - break ; - default: + getMultiplexer()->recvSingleChunkCRCRequest(virtual_peer_id,hash,item->chunk_number) ; + } + } + break ; + default: FTSERVER_ERROR() << "WARNING: Unknown packet type received: sub_id=" << reinterpret_cast(i->PacketSubType()) << ". Is somebody trying to poison you ?" << std::endl ; - } + } } /* NB: The rsCore lock must be activated before calling this. @@ -1492,126 +1492,126 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i, */ int ftServer::tick() { - bool moreToTick = false ; + bool moreToTick = false ; - if(handleIncoming()) - moreToTick = true; + if(handleIncoming()) + moreToTick = true; - static time_t last_law_priority_tasks_handling_time = 0 ; - time_t now = time(NULL) ; + static time_t last_law_priority_tasks_handling_time = 0 ; + time_t now = time(NULL) ; - if(last_law_priority_tasks_handling_time + FILE_TRANSFER_LOW_PRIORITY_TASKS_PERIOD < now) - { - last_law_priority_tasks_handling_time = now ; + if(last_law_priority_tasks_handling_time + FILE_TRANSFER_LOW_PRIORITY_TASKS_PERIOD < now) + { + last_law_priority_tasks_handling_time = now ; - mFtDataplex->deleteUnusedServers() ; - mFtDataplex->handlePendingCrcRequests() ; - mFtDataplex->dispatchReceivedChunkCheckSum() ; - } + mFtDataplex->deleteUnusedServers() ; + mFtDataplex->handlePendingCrcRequests() ; + mFtDataplex->dispatchReceivedChunkCheckSum() ; + } - return moreToTick; + return moreToTick; } int ftServer::handleIncoming() { - // now File Input. - int nhandled = 0 ; + // now File Input. + int nhandled = 0 ; - RsItem *item = NULL ; + RsItem *item = NULL ; - while(NULL != (item = recvItem())) - { - nhandled++ ; + while(NULL != (item = recvItem())) + { + nhandled++ ; - switch(item->PacketSubType()) - { - case RS_PKT_SUBTYPE_FT_DATA_REQUEST: - { - RsFileTransferDataRequestItem *f = dynamic_cast(item) ; - if (f) - { + switch(item->PacketSubType()) + { + case RS_PKT_SUBTYPE_FT_DATA_REQUEST: + { + RsFileTransferDataRequestItem *f = dynamic_cast(item) ; + if (f) + { #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "ftServer::handleIncoming: received data request for hash " << f->file.hash << ", offset=" << f->fileoffset << ", chunk size=" << f->chunksize << std::endl; #endif - mFtDataplex->recvDataRequest(f->PeerId(), f->file.hash, f->file.filesize, f->fileoffset, f->chunksize); - } - } - break ; + mFtDataplex->recvDataRequest(f->PeerId(), f->file.hash, f->file.filesize, f->fileoffset, f->chunksize); + } + } + break ; - case RS_PKT_SUBTYPE_FT_DATA: - { - RsFileTransferDataItem *f = dynamic_cast(item) ; - if (f) - { + case RS_PKT_SUBTYPE_FT_DATA: + { + RsFileTransferDataItem *f = dynamic_cast(item) ; + if (f) + { #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "ftServer::handleIncoming: received data for hash " << f->fd.file.hash << ", offset=" << f->fd.file_offset << ", chunk size=" << f->fd.binData.bin_len << std::endl; #endif - mFtDataplex->recvData(f->PeerId(), f->fd.file.hash, f->fd.file.filesize, f->fd.file_offset, f->fd.binData.bin_len, f->fd.binData.bin_data); + mFtDataplex->recvData(f->PeerId(), f->fd.file.hash, f->fd.file.filesize, f->fd.file_offset, f->fd.binData.bin_len, f->fd.binData.bin_data); - /* we've stolen the data part -> so blank before delete - */ - f->fd.binData.TlvShallowClear(); - } - } - break ; + /* we've stolen the data part -> so blank before delete + */ + f->fd.binData.TlvShallowClear(); + } + } + break ; - case RS_PKT_SUBTYPE_FT_CHUNK_MAP_REQUEST: - { - RsFileTransferChunkMapRequestItem *f = dynamic_cast(item) ; - if (f) - { + case RS_PKT_SUBTYPE_FT_CHUNK_MAP_REQUEST: + { + RsFileTransferChunkMapRequestItem *f = dynamic_cast(item) ; + if (f) + { #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "ftServer::handleIncoming: received chunkmap request for hash " << f->hash << ", client=" << f->is_client << std::endl; #endif - mFtDataplex->recvChunkMapRequest(f->PeerId(), f->hash,f->is_client) ; - } - } - break ; + mFtDataplex->recvChunkMapRequest(f->PeerId(), f->hash,f->is_client) ; + } + } + break ; - case RS_PKT_SUBTYPE_FT_CHUNK_MAP: - { - RsFileTransferChunkMapItem *f = dynamic_cast(item) ; - if (f) - { + case RS_PKT_SUBTYPE_FT_CHUNK_MAP: + { + RsFileTransferChunkMapItem *f = dynamic_cast(item) ; + if (f) + { #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "ftServer::handleIncoming: received chunkmap for hash " << f->hash << ", client=" << f->is_client << /*", map=" << f->compressed_map <<*/ std::endl; #endif - mFtDataplex->recvChunkMap(f->PeerId(), f->hash,f->compressed_map,f->is_client) ; - } - } - break ; + mFtDataplex->recvChunkMap(f->PeerId(), f->hash,f->compressed_map,f->is_client) ; + } + } + break ; - case RS_PKT_SUBTYPE_FT_CHUNK_CRC_REQUEST: - { - RsFileTransferSingleChunkCrcRequestItem *f = dynamic_cast(item) ; - if (f) - { + case RS_PKT_SUBTYPE_FT_CHUNK_CRC_REQUEST: + { + RsFileTransferSingleChunkCrcRequestItem *f = dynamic_cast(item) ; + if (f) + { #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "ftServer::handleIncoming: received single chunk crc req for hash " << f->hash << ", chunk number=" << f->chunk_number << std::endl; #endif - mFtDataplex->recvSingleChunkCRCRequest(f->PeerId(), f->hash,f->chunk_number) ; - } - } - break ; + mFtDataplex->recvSingleChunkCRCRequest(f->PeerId(), f->hash,f->chunk_number) ; + } + } + break ; - case RS_PKT_SUBTYPE_FT_CHUNK_CRC: - { - RsFileTransferSingleChunkCrcItem *f = dynamic_cast(item) ; - if (f) - { + case RS_PKT_SUBTYPE_FT_CHUNK_CRC: + { + RsFileTransferSingleChunkCrcItem *f = dynamic_cast(item) ; + if (f) + { #ifdef SERVER_DEBUG FTSERVER_DEBUG() << "ftServer::handleIncoming: received single chunk crc req for hash " << f->hash << ", chunk number=" << f->chunk_number << ", checksum = " << f->check_sum << std::endl; #endif - mFtDataplex->recvSingleChunkCRC(f->PeerId(), f->hash,f->chunk_number,f->check_sum); - } - } - break ; - } + mFtDataplex->recvSingleChunkCRC(f->PeerId(), f->hash,f->chunk_number,f->check_sum); + } + } + break ; + } - delete item ; - } + delete item ; + } - return nhandled; + return nhandled; } /********************************** @@ -1623,11 +1623,11 @@ int ftServer::handleIncoming() bool ftServer::addConfiguration(p3ConfigMgr *cfgmgr) { - /* add all the subbits to config mgr */ + /* add all the subbits to config mgr */ cfgmgr->addConfiguration("ft_database.cfg", mFileDatabase); - cfgmgr->addConfiguration("ft_extra.cfg", mFtExtra); - cfgmgr->addConfiguration("ft_transfers.cfg", mFtController); + cfgmgr->addConfiguration("ft_extra.cfg", mFtExtra); + cfgmgr->addConfiguration("ft_transfers.cfg", mFtController); - return true; + return true; } diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index 29be7aa90..bbb76a63a 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -219,7 +219,7 @@ public: /*************** Data Transfer Interface ***********************/ /***************************************************************/ public: - virtual bool activateTunnels(const RsFileHash& hash,TransferRequestFlags flags,bool onoff); + virtual bool activateTunnels(const RsFileHash& hash,uint32_t default_encryption_policy,TransferRequestFlags flags,bool onoff); virtual bool sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data); virtual bool sendDataRequest(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize); From 5aef67d33287411125485812bff7ffa6aed45ea4 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Wed, 2 Nov 2016 21:31:14 +0100 Subject: [PATCH 30/52] fixed tooltips in ShareManager, and fixed anonymous search mechanism --- libretroshare/src/retroshare/rsfiles.h | 3 ++- libretroshare/src/rsserver/p3peers.cc | 4 +++- libretroshare/src/turtle/p3turtle.cc | 4 ++-- retroshare-gui/src/gui/SharedFilesDialog.ui | 4 ++-- .../src/gui/common/GroupFlagsWidget.cpp | 16 ++++++++++------ 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index c40ce9d54..b45aedcc7 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -76,7 +76,8 @@ const FileSearchFlags RS_FILE_HINTS_SPEC_ONLY ( 0x01000000 ); const FileSearchFlags RS_FILE_HINTS_NETWORK_WIDE ( 0x00000080 );// anonymously shared over network const FileSearchFlags RS_FILE_HINTS_BROWSABLE ( 0x00000100 );// browsable by friends -const FileSearchFlags RS_FILE_HINTS_PERMISSION_MASK ( 0x00000180 );// OR of the last two flags. Used to filter out. +const FileSearchFlags RS_FILE_HINTS_SEARCHABLE ( 0x00000200 );// browsable by friends +const FileSearchFlags RS_FILE_HINTS_PERMISSION_MASK ( 0x00000380 );// OR of the last tree flags. Used to filter out. // Flags used when requesting a transfer // diff --git a/libretroshare/src/rsserver/p3peers.cc b/libretroshare/src/rsserver/p3peers.cc index aea128867..d4b5fe332 100644 --- a/libretroshare/src/rsserver/p3peers.cc +++ b/libretroshare/src/rsserver/p3peers.cc @@ -1379,12 +1379,14 @@ FileSearchFlags p3Peers::computePeerPermissionFlags(const RsPeerId& peer_ssl_id, } bool network_wide = (share_flags & DIR_FLAGS_ANONYMOUS_DOWNLOAD) ;//|| ( (share_flags & DIR_FLAGS_NETWORK_WIDE_GROUPS) && found) ; - bool browsable = (share_flags & DIR_FLAGS_BROWSABLE) && found ; + bool browsable = (share_flags & DIR_FLAGS_BROWSABLE) && found ; + bool searchable = (share_flags & DIR_FLAGS_ANONYMOUS_SEARCH) ; FileSearchFlags final_flags ; if(network_wide) final_flags |= RS_FILE_HINTS_NETWORK_WIDE ; if(browsable ) final_flags |= RS_FILE_HINTS_BROWSABLE ; + if(searchable ) final_flags |= RS_FILE_HINTS_SEARCHABLE ; return final_flags ; } diff --git a/libretroshare/src/turtle/p3turtle.cc b/libretroshare/src/turtle/p3turtle.cc index 8208c08b8..bb4684f01 100644 --- a/libretroshare/src/turtle/p3turtle.cc +++ b/libretroshare/src/turtle/p3turtle.cc @@ -1729,7 +1729,7 @@ void RsTurtleStringSearchRequestItem::performLocalSearch(std::listsearch()" << std::endl ; #endif // now, search! - rsFiles->SearchKeywords(words, initialResults,RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_NETWORK_WIDE,PeerId()); + rsFiles->SearchKeywords(words, initialResults,RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_SEARCHABLE,PeerId()); #ifdef P3TURTLE_DEBUG std::cerr << initialResults.size() << " matches found." << std::endl ; @@ -1767,7 +1767,7 @@ void RsTurtleRegExpSearchRequestItem::performLocalSearch(std::listSearchBoolExp(exp,initialResults,RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_NETWORK_WIDE,PeerId()); + rsFiles->SearchBoolExp(exp,initialResults,RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_SEARCHABLE,PeerId()); result.clear() ; diff --git a/retroshare-gui/src/gui/SharedFilesDialog.ui b/retroshare-gui/src/gui/SharedFilesDialog.ui index 25f9337fa..f408098c5 100644 --- a/retroshare-gui/src/gui/SharedFilesDialog.ui +++ b/retroshare-gui/src/gui/SharedFilesDialog.ui @@ -6,7 +6,7 @@ 0 0 - 737 + 1156 402 @@ -86,7 +86,7 @@ - Add Share + Configure shared directories diff --git a/retroshare-gui/src/gui/common/GroupFlagsWidget.cpp b/retroshare-gui/src/gui/common/GroupFlagsWidget.cpp index ad11c7c40..9a24c1300 100644 --- a/retroshare-gui/src/gui/common/GroupFlagsWidget.cpp +++ b/retroshare-gui/src/gui/common/GroupFlagsWidget.cpp @@ -96,16 +96,20 @@ void GroupFlagsWidget::update_button_state(bool b,int button_id) { QString tip_on, tip_off; switch (button_id) { - case 2: - tip_on = tr("Directory is visible to some friends (see list at right)"); - tip_off = tr("Directory is NOT visible to any friend"); + case INDEX_BROWSABLE: + tip_on = tr("Directory content is visible to friend nodes (see list at right)"); + tip_off = tr("Directory content is NOT visible to friend nodes"); break; - case 0: + case INDEX_ANON_SEARCH: tip_on = tr("Directory can be searched anonymously"); tip_off = tr("Directory cannot be searched anonymously"); break; - case 1: - tip_on = tr("Files can be downloaded anonymously"); + case INDEX_ANON_DL: + if(_buttons[INDEX_ANON_SEARCH]->isChecked()) + tip_on = tr("Files can be accessed using anonymous tunnels"); + else + tip_on = tr("Files can be accessed using anonymous & end-to-end encrypted tunnels"); + tip_off = tr("Files cannot be downloaded anonymously"); break; default: From 1c2cfb2a031a1cfbebdf9d8961483c4a67f814e5 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Wed, 2 Nov 2016 21:32:14 +0100 Subject: [PATCH 31/52] removed debug info in ftServer --- libretroshare/src/ft/ftserver.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index b24b034cc..3ebc0bc18 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -57,8 +57,6 @@ const int ftserverzone = 29539; * #define SERVER_DEBUG_CACHE 1 ***/ -#define SERVER_DEBUG 1 - #define FTSERVER_DEBUG() std::cerr << time(NULL) << " : FILE_SERVER : " << __FUNCTION__ << " : " #define FTSERVER_ERROR() std::cerr << "(EE) FILE_SERVER ERROR : " From 2db8dbd45fc9e5093412d37ae1fe2bba8d142d57 Mon Sep 17 00:00:00 2001 From: Phenom Date: Sat, 16 Jul 2016 23:10:00 +0200 Subject: [PATCH 32/52] Fix El Capitan OSX 10.11 Compil --- MacOS_X_InstallGuide.md | 76 ++- libresapi/src/libresapi.pro | 3 +- libretroshare/src/libretroshare.pro | 5 +- libretroshare/src/util/rsthreads.cc | 34 +- openpgpsdk/src/openpgpsdk.pro | 30 +- openpgpsdk/src/openpgpsdk/opsdir.c | 3 +- retroshare-gui/src/gui/GenCertDialog.cpp | 6 +- retroshare-gui/src/retroshare-gui.pro | 3 + retroshare.pri | 8 +- tests/librssimulator/librssimulator.pro | 47 +- tests/unittests/unittests.pro | 735 ++++++++++++----------- 11 files changed, 502 insertions(+), 448 deletions(-) diff --git a/MacOS_X_InstallGuide.md b/MacOS_X_InstallGuide.md index ab20893e3..f79d5fa0e 100644 --- a/MacOS_X_InstallGuide.md +++ b/MacOS_X_InstallGuide.md @@ -1,65 +1,83 @@ -##Compilation on MacOS +# Compilation on MacOS -### Qt Installation +## Qt Installation -Install Qt via: [Qt Download](http://www.qt.io/download/) +Install Qt via: [Qt Download](http://www.qt.io/download/) -Use default options. -Add to the PATH environment variable with this temporary solution. +Use default options. And add Qt Script support. - export PATH=/users/$USER/Qt/5.5/clang_64/bin:$PATH +Add to the PATH environment variable by editing your *~/.profile* file. + + export PATH="/users/$USER/Qt/5.5/clang_64/bin:$PATH" Depends on wich version of Qt you use. -###MacPort Installation +## ***Choose if you use MacPort or HomeBrew*** + +### MacPort Installation Install MacPort and XCode following this guide: [MacPort and XCode](http://guide.macports.org/#installing.xcode) -Start XCode to get it updated and to able C compiler to create executables. +Start XCode to get it updated and to able C compiler to create executables. -###Install libraries +#### Install libraries $sudo port -v selfupdate $sudo port install openssl $sudo port install miniupnpc + $sudo port install libmicrohttpd For VOIP Plugin: $sudo port install speex-devel $sudo port install opencv -Get Your OSX SDK if missing: [MacOSX-SDKs](https://github.com/phracker/MacOSX-SDKs) +Get Your OSX SDK if missing: [MacOSX-SDKs](https://github.com/phracker/MacOSX-SDKs) -###Last Settings +### HOMEBREW Installation -In QtCreator Option Git add its path: +Install HomeBrew following this guide: [HomeBrew](http://brew.sh/) - C:\Program Files\Git\bin +Install XCode command line developer tools: + + $xcode-select --install + +Start XCode to get it updated and to able C compiler to create executables. + +#### Install libraries + + $brew install openssl + $brew install miniupnpc + $brew install libmicrohttpd -and select "Pull" with "Rebase" +If you have error in linking, run this: -###Compil missing libraries -####SQLCipher + $sudo chown -R $(whoami) /usr/local/lib/pkgconfig + +For VOIP Plugin: + + $brew install speex + $brew install homebrew/science/opencv + $brew install ffmpeg + +Get Your OSX SDK if missing: [MacOSX-SDKs](https://github.com/phracker/MacOSX-SDKs) + +## Last Settings + +In QtCreator Option Git select "Pull" with "Rebase" + +## Compil missing libraries +### SQLCipher cd git clone https://github.com/sqlcipher/sqlcipher.git cd sqlcipher - ./configure --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC" LDFLAGS="-lcrypto" + ./configure --disable-shared --disable-tcl --enable-static --enable-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC -I/opt/local/include" LDFLAGS="-lcrypto" make sudo make install NOTE, might be necessary to *chmod 000 /usr/local/ssl* temporarily during *./configure* if -homebrew uses newer, non-stock ssl dependencies found there. configure might get confused. - -####libMicroHTTPD -The one with port don't have good support. - - cd - wget http://ftpmirror.gnu.org/libmicrohttpd/libmicrohttpd-0.9.46.tar.gz - tar zxvf libmicrohttpd-0.9.46.tar.gz - cd libmicrohttpd-0.9.46 - bash ./configure - sudo make install +homebrew uses newer, non-stock ssl dependencies found there. Configure might get confused. You can now compile RS into Qt Creator or with terminal @@ -68,4 +86,6 @@ You can now compile RS into Qt Creator or with terminal cd retroshare qmake; make +You can change Target and SDK in *./retroshare.pri:82* changing value of QMAKE_MACOSX_DEPLOYMENT_TARGET and QMAKE_MAC_SDK + You can find compiled application on *./retroshare/retroshare-gui/src/RetroShare06.app* diff --git a/libresapi/src/libresapi.pro b/libresapi/src/libresapi.pro index b76b2a30b..f310198fb 100644 --- a/libresapi/src/libresapi.pro +++ b/libresapi/src/libresapi.pro @@ -113,7 +113,8 @@ libresapihttpserver { } else { mac { INCLUDEPATH += . $$INC_DIR - for(lib, LIB_DIR):exists($$lib/libmicrohttpd.a){ LIBS *= $$lib/libmicrohttpd.a} + #for(lib, LIB_DIR):exists($$lib/libmicrohttpd.a){ LIBS *= $$lib/libmicrohttpd.a} + LIBS *= -lmicrohttpd } else { LIBS *= -lmicrohttpd } diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 85ff8dce7..7ca15b08b 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -295,7 +295,7 @@ mac { OBJECTS_DIR = temp/obj MOC_DIR = temp/moc #DEFINES = WINDOWS_SYS WIN32 STATICLIB MINGW - DEFINES *= MINIUPNPC_VERSION=13 + #DEFINES *= MINIUPNPC_VERSION=13 CONFIG += upnp_miniupnpc CONFIG += c++11 @@ -305,7 +305,7 @@ mac { #CONFIG += zcnatassist # Beautiful Hack to fix 64bit file access. - QMAKE_CXXFLAGS *= -Dfseeko64=fseeko -Dftello64=ftello -Dfopen64=fopen -Dvstatfs64=vstatfs + QMAKE_CXXFLAGS *= -Dfseeko64=fseeko -Dftello64=ftello -Dfopen64=fopen -Dvstatfs64=vstatfs #GPG_ERROR_DIR = ../../../../libgpg-error-1.7 #GPGME_DIR = ../../../../gpgme-1.1.8 @@ -315,6 +315,7 @@ mac { DEPENDPATH += . $$INC_DIR INCLUDEPATH += . $$INC_DIR + INCLUDEPATH += ../../../. # We need a explicit path here, to force using the home version of sqlite3 that really encrypts the database. LIBS += /usr/local/lib/libsqlcipher.a diff --git a/libretroshare/src/util/rsthreads.cc b/libretroshare/src/util/rsthreads.cc index bf2f34042..fcf4483be 100644 --- a/libretroshare/src/util/rsthreads.cc +++ b/libretroshare/src/util/rsthreads.cc @@ -30,7 +30,17 @@ #include #include +#ifdef __APPLE__ +int __attribute__((weak)) pthread_setname_np(const char *__buf) ; +int RS_pthread_setname_np(pthread_t /*__target_thread*/, const char *__buf) { + return pthread_setname_np(__buf); +} +#else int __attribute__((weak)) pthread_setname_np(pthread_t __target_thread, const char *__buf) ; +int RS_pthread_setname_np(pthread_t __target_thread, const char *__buf) { + return pthread_setname_np(__target_thread, __buf); +} +#endif #ifdef RSMUTEX_DEBUG #include @@ -167,19 +177,21 @@ void RsThread::start(const std::string &threadName) // set name if(pthread_setname_np) - if(!threadName.empty()) - { - // thread names are restricted to 16 characters including the terminating null byte - if(threadName.length() > 15) - { + { + if(!threadName.empty()) + { + // thread names are restricted to 16 characters including the terminating null byte + if(threadName.length() > 15) + { #ifdef DEBUG_THREADS - THREAD_DEBUG << "RsThread::start called with to long name '" << name << "' truncating..." << std::endl; + THREAD_DEBUG << "RsThread::start called with to long name '" << name << "' truncating..." << std::endl; #endif - pthread_setname_np(mTid, threadName.substr(0, 15).c_str()); - } else { - pthread_setname_np(mTid, threadName.c_str()); - } - } + RS_pthread_setname_np(mTid, threadName.substr(0, 15).c_str()); + } else { + RS_pthread_setname_np(mTid, threadName.c_str()); + } + } + } } else { diff --git a/openpgpsdk/src/openpgpsdk.pro b/openpgpsdk/src/openpgpsdk.pro index 2cee7847d..f624619fc 100644 --- a/openpgpsdk/src/openpgpsdk.pro +++ b/openpgpsdk/src/openpgpsdk.pro @@ -1,11 +1,7 @@ !include("../../retroshare.pri"): error("Could not include file ../../retroshare.pri") TEMPLATE = lib -macx { - CONFIG = staticlib -} else { - CONFIG += staticlib -} +CONFIG += staticlib DEFINES *= OPENSSL_NO_IDEA @@ -13,8 +9,8 @@ QMAKE_CXXFLAGS *= -Wall -Werror -W TARGET = ops DESTDIR = lib -DEPENDPATH += . -INCLUDEPATH += . +DEPENDPATH += . $$INC_DIR +INCLUDEPATH += . $$INC_DIR #################################### Windows ##################################### @@ -34,9 +30,13 @@ win32 { # Switch on optimization for debug version #QMAKE_CXXFLAGS_DEBUG += -O2 #QMAKE_CFLAGS_DEBUG += -O2 +} - DEPENDPATH += $$INC_DIR - INCLUDEPATH += $$INC_DIR + +macx { + for(lib, LIB_DIR):LIBS += -L"$$lib" + for(bin, BIN_DIR):LIBS += -L"$$bin" + DEFINES += OPENSSL_NO_CAMELLIA } # Input @@ -73,8 +73,10 @@ HEADERS += openpgpsdk/writer.h \ openpgpsdk/armour.h \ openpgpsdk/parse_local.h \ openpgpsdk/keyring_local.h \ - openpgpsdk/opsdir.h \ - openpgpsdk/opsstring.h + openpgpsdk/opsdir.h +win32{ +HEADERS += openpgpsdk/opsstring.h +} SOURCES += openpgpsdk/accumulate.c \ openpgpsdk/compress.c \ @@ -113,5 +115,7 @@ SOURCES += openpgpsdk/accumulate.c \ openpgpsdk/writer_memory.c \ openpgpsdk/writer_skey_checksum.c \ openpgpsdk/writer_stream_encrypt_se_ip.c \ - openpgpsdk/opsdir.c \ - openpgpsdk/opsstring.c + openpgpsdk/opsdir.c +win32{ +SOURCES += openpgpsdk/opsstring.c +} diff --git a/openpgpsdk/src/openpgpsdk/opsdir.c b/openpgpsdk/src/openpgpsdk/opsdir.c index df7ce76c2..b966f090f 100644 --- a/openpgpsdk/src/openpgpsdk/opsdir.c +++ b/openpgpsdk/src/openpgpsdk/opsdir.c @@ -1,6 +1,7 @@ #include "opsdir.h" +#ifdef WIN32 #include "opsstring.h" - +#endif #include int ops_open(const char* filename, int flag, int pmode) diff --git a/retroshare-gui/src/gui/GenCertDialog.cpp b/retroshare-gui/src/gui/GenCertDialog.cpp index a6f62a4ef..d9b2c7c75 100644 --- a/retroshare-gui/src/gui/GenCertDialog.cpp +++ b/retroshare-gui/src/gui/GenCertDialog.cpp @@ -584,10 +584,13 @@ void GenCertDialog::genPerson() QCoreApplication::processEvents(); QAbstractEventDispatcher* ed = QAbstractEventDispatcher::instance(); + std::cout << "Waiting ed->processEvents()" << std::endl; + time_t waitEnd = time(NULL) + 10;//Wait no more than 10 sec to processEvents if (ed->hasPendingEvents()) - while(ed->processEvents(QEventLoop::AllEvents)); + while(ed->processEvents(QEventLoop::AllEvents) && (time(NULL) < waitEnd)); std::string email_str = "" ; + std::cout << "RsAccounts::GeneratePGPCertificate" << std::endl; RsAccounts::GeneratePGPCertificate( ui.name_input->text().toUtf8().constData(), email_str.c_str(), @@ -609,6 +612,7 @@ void GenCertDialog::genPerson() std::cerr << "GenCertDialog::genPerson() Generating SSL cert with gpg id : " << PGPId << std::endl; std::string err; this->hide();//To show dialog asking password PGP Key. + std::cout << "RsAccounts::GenerateSSLCertificate" << std::endl; bool okGen = RsAccounts::GenerateSSLCertificate(PGPId, "", genLoc, "", isHiddenLoc, sslPasswd, sslId, err); if (okGen) diff --git a/retroshare-gui/src/retroshare-gui.pro b/retroshare-gui/src/retroshare-gui.pro index b548108ca..ea2bc97e6 100644 --- a/retroshare-gui/src/retroshare-gui.pro +++ b/retroshare-gui/src/retroshare-gui.pro @@ -234,6 +234,9 @@ macx { mac_icon.files = $$files($$PWD/rsMacIcon.icns) mac_icon.path = Contents/Resources QMAKE_BUNDLE_DATA += mac_icon + mac_webui.files = $$files($$PWD/../../libresapi/src/webui) + mac_webui.path = Contents/Resources + QMAKE_BUNDLE_DATA += mac_webui CONFIG += version_detail_bash_script LIBS += -lssl -lcrypto -lz diff --git a/retroshare.pri b/retroshare.pri index 5d8572807..f0f016d38 100644 --- a/retroshare.pri +++ b/retroshare.pri @@ -77,12 +77,12 @@ macx { LIB_DIR += "/usr/local/lib" LIB_DIR += "/opt/local/lib" !QMAKE_MACOSX_DEPLOYMENT_TARGET { - message(***retroshare.pri: No Target, set it to MacOS 10.10 ) - QMAKE_MACOSX_DEPLOYMENT_TARGET=10.10 + message(***retroshare.pri: No Target. Set it to MacOS 10.11 ) + QMAKE_MACOSX_DEPLOYMENT_TARGET=10.11 } !QMAKE_MAC_SDK { - message(***retroshare.pri: No SDK, set it to MacOS 10.10 ) - QMAKE_MAC_SDK = macosx10.10 + message(***retroshare.pri: No SDK. Set it to MacOS 10.11 ) + QMAKE_MAC_SDK = macosx10.11 } CONFIG += c++11 } diff --git a/tests/librssimulator/librssimulator.pro b/tests/librssimulator/librssimulator.pro index 9ef336b57..94c942f53 100644 --- a/tests/librssimulator/librssimulator.pro +++ b/tests/librssimulator/librssimulator.pro @@ -182,33 +182,40 @@ win32 { ################################# MacOSX ########################################## mac { - QMAKE_CC = $${QMAKE_CXX} - OBJECTS_DIR = temp/obj - MOC_DIR = temp/moc - #DEFINES = WINDOWS_SYS WIN32 STATICLIB MINGW - #DEFINES *= MINIUPNPC_VERSION=13 - DESTDIR = lib + QMAKE_CC = $${QMAKE_CXX} + OBJECTS_DIR = temp/obj + MOC_DIR = temp/moc + #DEFINES = WINDOWS_SYS WIN32 STATICLIB MINGW + #DEFINES *= MINIUPNPC_VERSION=13 + DESTDIR = lib - CONFIG += upnp_miniupnpc + CONFIG += upnp_miniupnpc - # zeroconf disabled at the end of libretroshare.pro (but need the code) - CONFIG += zeroconf - CONFIG += zcnatassist + # zeroconf disabled at the end of libretroshare.pro (but need the code) + #CONFIG += zeroconf + #CONFIG += zcnatassist - # Beautiful Hack to fix 64bit file access. - QMAKE_CXXFLAGS *= -Dfseeko64=fseeko -Dftello64=ftello -Dfopen64=fopen -Dvstatfs64=vstatfs + # Beautiful Hack to fix 64bit file access. + QMAKE_CXXFLAGS *= -Dfseeko64=fseeko -Dftello64=ftello -Dfopen64=fopen -Dvstatfs64=vstatfs - UPNPC_DIR = ../../../miniupnpc-1.0 - #GPG_ERROR_DIR = ../../../../libgpg-error-1.7 - #GPGME_DIR = ../../../../gpgme-1.1.8 + #UPNPC_DIR = ../../../miniupnpc-1.0 + #GPG_ERROR_DIR = ../../../../libgpg-error-1.7 + #GPGME_DIR = ../../../../gpgme-1.1.8 + #OPENPGPSDK_DIR = ../../openpgpsdk/src + #INCLUDEPATH += . $${UPNPC_DIR} + #INCLUDEPATH += $${OPENPGPSDK_DIR} - OPENPGPSDK_DIR = ../../openpgpsdk/src + #for(lib, LIB_DIR):exists($$lib/libminiupnpc.a){ LIBS += $$lib/libminiupnpc.a} + for(lib, LIB_DIR):LIBS += -L"$$lib" + for(bin, BIN_DIR):LIBS += -L"$$bin" - INCLUDEPATH += . $${UPNPC_DIR} - INCLUDEPATH += $${OPENPGPSDK_DIR} + DEPENDPATH += . $$INC_DIR + INCLUDEPATH += . $$INC_DIR + INCLUDEPATH += ../../../. - #../openpgpsdk - #INCLUDEPATH += . $${UPNPC_DIR} $${GPGME_DIR}/src $${GPG_ERROR_DIR}/src + # We need a explicit path here, to force using the home version of sqlite3 that really encrypts the database. + LIBS += /usr/local/lib/libsqlcipher.a + #LIBS += -lsqlite3 } ################################# FreeBSD ########################################## diff --git a/tests/unittests/unittests.pro b/tests/unittests/unittests.pro index d0485ca92..a023133b6 100644 --- a/tests/unittests/unittests.pro +++ b/tests/unittests/unittests.pro @@ -1,156 +1,156 @@ !include("../../retroshare.pri"): error("Could not include file ../../retroshare.pri") -QT += network xml script -CONFIG += bitdht - -CONFIG += gxs debug - -gxs { - DEFINES += RS_ENABLE_GXS -} - -TEMPLATE = app -TARGET = unittests - -OPENPGPSDK_DIR = ../../openpgpsdk/src -INCLUDEPATH *= $${OPENPGPSDK_DIR} ../openpgpsdk - -# it is impossible to use precompield googletest lib -# because googletest must be compiled with same compiler flags as the tests! -!exists(../googletest/googletest/src/gtest-all.cc){ - message(trying to git clone googletest...) - !system(git clone https://github.com/google/googletest.git ../googletest){ - error(Could not git clone googletest files. You can manually download them to /tests/googletest) - } -} - -INCLUDEPATH += \ - ../googletest/googletest/include \ - ../googletest/googletest - -SOURCES += ../googletest/googletest/src/gtest-all.cc - -################################# Linux ########################################## -# Put lib dir in QMAKE_LFLAGS so it appears before -L/usr/lib -linux-* { - #CONFIG += version_detail_bash_script - QMAKE_CXXFLAGS *= -D_FILE_OFFSET_BITS=64 - - PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a - PRE_TARGETDEPS *= ../../openpgpsdk/src/lib/libops.a - - LIBS += ../../libretroshare/src/lib/libretroshare.a - LIBS += ../librssimulator/lib/librssimulator.a - LIBS += ../../openpgpsdk/src/lib/libops.a -lbz2 - LIBS += -lssl -lupnp -lixml -lXss -lgnome-keyring - LIBS *= -lcrypto -ldl -lX11 -lz -lpthread - - #LIBS += ../../supportlibs/pegmarkdown/lib/libpegmarkdown.a - - contains(CONFIG, NO_SQLCIPHER) { - DEFINES *= NO_SQLCIPHER - PKGCONFIG *= sqlite3 - } else { - # We need a explicit path here, to force using the home version of sqlite3 that really encrypts the database. - - SQLCIPHER_OK = $$system(pkg-config --exists sqlcipher && echo yes) - isEmpty(SQLCIPHER_OK) { - # We need a explicit path here, to force using the home version of sqlite3 that really encrypts the database. - - ! exists(../../../lib/sqlcipher/.libs/libsqlcipher.a) { - message(../../../lib/sqlcipher/.libs/libsqlcipher.a does not exist) - error(Please fix this and try again. Will stop now.) - } - - LIBS += ../../../lib/sqlcipher/.libs/libsqlcipher.a - INCLUDEPATH += ../../../lib/sqlcipher/src/ - INCLUDEPATH += ../../../lib/sqlcipher/tsrc/ - } else { - LIBS += -lsqlcipher - } - } - - - LIBS *= -lglib-2.0 - LIBS *= -rdynamic - DEFINES *= HAVE_XSS # for idle time, libx screensaver extensions - DEFINES *= HAS_GNOME_KEYRING -} - -linux-g++ { - OBJECTS_DIR = temp/linux-g++/obj -} - -linux-g++-64 { - OBJECTS_DIR = temp/linux-g++-64/obj -} - -#################### Cross compilation for windows under Linux ################### - -win32-x-g++ { - OBJECTS_DIR = temp/win32-x-g++/obj - - LIBS += ../../libretroshare/src/lib.win32xgcc/libretroshare.a - LIBS += ../../../../lib/win32-x-g++-v0.5/libssl.a - LIBS += ../../../../lib/win32-x-g++-v0.5/libcrypto.a - LIBS += ../../../../lib/win32-x-g++-v0.5/libgpgme.dll.a - LIBS += ../../../../lib/win32-x-g++-v0.5/libminiupnpc.a - LIBS += ../../../../lib/win32-x-g++-v0.5/libz.a - LIBS += -L${HOME}/.wine/drive_c/pthreads/lib -lpthreadGCE2 - LIBS += -lQtUiTools - LIBS += -lws2_32 -luuid -lole32 -liphlpapi -lcrypt32 -gdi32 - LIBS += -lole32 -lwinmm - - DEFINES *= WINDOWS_SYS WIN32 WIN32_CROSS_UBUNTU - - INCLUDEPATH += ../../../../gpgme-1.1.8/src/ - INCLUDEPATH += ../../../../libgpg-error-1.7/src/ - - RC_FILE = gui/images/retroshare_win.rc -} - -#################################### Windows ##################################### - -win32 { - # Switch on extra warnings - QMAKE_CFLAGS += -Wextra - QMAKE_CXXFLAGS += -Wextra - +QT += network xml script +CONFIG += bitdht + +CONFIG += gxs debug + +gxs { + DEFINES += RS_ENABLE_GXS +} + +TEMPLATE = app +TARGET = unittests + +OPENPGPSDK_DIR = ../../openpgpsdk/src +INCLUDEPATH *= $${OPENPGPSDK_DIR} ../openpgpsdk + +# it is impossible to use precompield googletest lib +# because googletest must be compiled with same compiler flags as the tests! +!exists(../googletest/googletest/src/gtest-all.cc){ + message(trying to git clone googletest...) + !system(git clone https://github.com/google/googletest.git ../googletest){ + error(Could not git clone googletest files. You can manually download them to /tests/googletest) + } +} + +INCLUDEPATH += \ + ../googletest/googletest/include \ + ../googletest/googletest + +SOURCES += ../googletest/googletest/src/gtest-all.cc + +################################# Linux ########################################## +# Put lib dir in QMAKE_LFLAGS so it appears before -L/usr/lib +linux-* { + #CONFIG += version_detail_bash_script + QMAKE_CXXFLAGS *= -D_FILE_OFFSET_BITS=64 + + PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a + PRE_TARGETDEPS *= ../../openpgpsdk/src/lib/libops.a + + LIBS += ../../libretroshare/src/lib/libretroshare.a + LIBS += ../librssimulator/lib/librssimulator.a + LIBS += ../../openpgpsdk/src/lib/libops.a -lbz2 + LIBS += -lssl -lupnp -lixml -lXss -lgnome-keyring + LIBS *= -lcrypto -ldl -lX11 -lz -lpthread + + #LIBS += ../../supportlibs/pegmarkdown/lib/libpegmarkdown.a + + contains(CONFIG, NO_SQLCIPHER) { + DEFINES *= NO_SQLCIPHER + PKGCONFIG *= sqlite3 + } else { + # We need a explicit path here, to force using the home version of sqlite3 that really encrypts the database. + + SQLCIPHER_OK = $$system(pkg-config --exists sqlcipher && echo yes) + isEmpty(SQLCIPHER_OK) { + # We need a explicit path here, to force using the home version of sqlite3 that really encrypts the database. + + ! exists(../../../lib/sqlcipher/.libs/libsqlcipher.a) { + message(../../../lib/sqlcipher/.libs/libsqlcipher.a does not exist) + error(Please fix this and try again. Will stop now.) + } + + LIBS += ../../../lib/sqlcipher/.libs/libsqlcipher.a + INCLUDEPATH += ../../../lib/sqlcipher/src/ + INCLUDEPATH += ../../../lib/sqlcipher/tsrc/ + } else { + LIBS += -lsqlcipher + } + } + + + LIBS *= -lglib-2.0 + LIBS *= -rdynamic + DEFINES *= HAVE_XSS # for idle time, libx screensaver extensions + DEFINES *= HAS_GNOME_KEYRING +} + +linux-g++ { + OBJECTS_DIR = temp/linux-g++/obj +} + +linux-g++-64 { + OBJECTS_DIR = temp/linux-g++-64/obj +} + +#################### Cross compilation for windows under Linux ################### + +win32-x-g++ { + OBJECTS_DIR = temp/win32-x-g++/obj + + LIBS += ../../libretroshare/src/lib.win32xgcc/libretroshare.a + LIBS += ../../../../lib/win32-x-g++-v0.5/libssl.a + LIBS += ../../../../lib/win32-x-g++-v0.5/libcrypto.a + LIBS += ../../../../lib/win32-x-g++-v0.5/libgpgme.dll.a + LIBS += ../../../../lib/win32-x-g++-v0.5/libminiupnpc.a + LIBS += ../../../../lib/win32-x-g++-v0.5/libz.a + LIBS += -L${HOME}/.wine/drive_c/pthreads/lib -lpthreadGCE2 + LIBS += -lQtUiTools + LIBS += -lws2_32 -luuid -lole32 -liphlpapi -lcrypt32 -gdi32 + LIBS += -lole32 -lwinmm + + DEFINES *= WINDOWS_SYS WIN32 WIN32_CROSS_UBUNTU + + INCLUDEPATH += ../../../../gpgme-1.1.8/src/ + INCLUDEPATH += ../../../../libgpg-error-1.7/src/ + + RC_FILE = gui/images/retroshare_win.rc +} + +#################################### Windows ##################################### + +win32 { + # Switch on extra warnings + QMAKE_CFLAGS += -Wextra + QMAKE_CXXFLAGS += -Wextra + # solve linker warnings because of the order of the libraries QMAKE_LFLAGS += -Wl,--start-group - # Switch off optimization for release version - QMAKE_CXXFLAGS_RELEASE -= -O2 - QMAKE_CXXFLAGS_RELEASE += -O0 - QMAKE_CFLAGS_RELEASE -= -O2 - QMAKE_CFLAGS_RELEASE += -O0 - - # Switch on optimization for debug version - #QMAKE_CXXFLAGS_DEBUG += -O2 - #QMAKE_CFLAGS_DEBUG += -O2 - - OBJECTS_DIR = temp/obj - #LIBS += -L"D/Qt/2009.03/qt/plugins/imageformats" - #QTPLUGIN += qjpeg - - PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a - PRE_TARGETDEPS *= ../librssimulator/lib/librssimulator.a - PRE_TARGETDEPS *= ../../openpgpsdk/src/lib/libops.a - + # Switch off optimization for release version + QMAKE_CXXFLAGS_RELEASE -= -O2 + QMAKE_CXXFLAGS_RELEASE += -O0 + QMAKE_CFLAGS_RELEASE -= -O2 + QMAKE_CFLAGS_RELEASE += -O0 + + # Switch on optimization for debug version + #QMAKE_CXXFLAGS_DEBUG += -O2 + #QMAKE_CFLAGS_DEBUG += -O2 + + OBJECTS_DIR = temp/obj + #LIBS += -L"D/Qt/2009.03/qt/plugins/imageformats" + #QTPLUGIN += qjpeg + + PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a + PRE_TARGETDEPS *= ../librssimulator/lib/librssimulator.a + PRE_TARGETDEPS *= ../../openpgpsdk/src/lib/libops.a + for(lib, LIB_DIR):LIBS += -L"$$lib" for(bin, BIN_DIR):LIBS += -L"$$bin" - LIBS += ../../libretroshare/src/lib/libretroshare.a + LIBS += ../../libretroshare/src/lib/libretroshare.a LIBS += ../librssimulator/lib/librssimulator.a - LIBS += ../../openpgpsdk/src/lib/libops.a -lbz2 - LIBS += -L"$$PWD/../../../lib" - - LIBS += -lssl -lcrypto -lpthread -lminiupnpc -lz - LIBS += -luuid -lole32 -liphlpapi -lcrypt32 -lgdi32 + LIBS += ../../openpgpsdk/src/lib/libops.a -lbz2 + LIBS += -L"$$PWD/../../../lib" + + LIBS += -lssl -lcrypto -lpthread -lminiupnpc -lz + LIBS += -luuid -lole32 -liphlpapi -lcrypt32 -lgdi32 LIBS += -lwinmm - - DEFINES *= WINDOWS_SYS WIN32_LEAN_AND_MEAN _USE_32BIT_TIME_T - + + DEFINES *= WINDOWS_SYS WIN32_LEAN_AND_MEAN _USE_32BIT_TIME_T + # create lib directory message(CHK_DIR_EXISTS=$(CHK_DIR_EXISTS)) message(MKDIR=$(MKDIR)) @@ -166,227 +166,228 @@ win32 { # Qt 4 QMAKE_RC += --include-dir=$$_PRO_FILE_PWD_/../../libretroshare/src } -} - -##################################### MacOS ###################################### - -macx { - # ENABLE THIS OPTION FOR Univeral Binary BUILD. - CONFIG += ppc x86 - QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.4 - - CONFIG += version_detail_bash_script - LIBS += ../../libretroshare/src/lib/libretroshare.a - LIBS += ../librssimulator/lib/librssimulator.a - LIBS += ../../openpgpsdk/src/lib/libops.a -lbz2 - LIBS += -lssl -lcrypto -lz - #LIBS += -lssl -lcrypto -lz -lgpgme -lgpg-error -lassuan - LIBS += ../../../miniupnpc-1.0/libminiupnpc.a - LIBS += -framework CoreFoundation - LIBS += -framework Security - - gxs { - LIBS += ../../supportlibs/pegmarkdown/lib/libpegmarkdown.a - - LIBS += ../../../lib/libsqlcipher.a - #LIBS += -lsqlite3 - - } - - - INCLUDEPATH += . - #DEFINES* = MAC_IDLE # for idle feature - CONFIG -= uitools - - -} - -##################################### FreeBSD ###################################### - -freebsd-* { - INCLUDEPATH *= /usr/local/include/gpgme - LIBS *= ../../libretroshare/src/lib/libretroshare.a - LIBS *= ../librssimulator/lib/librssimulator.a - LIBS *= -lssl - LIBS *= -lgpgme - LIBS *= -lupnp - LIBS *= -lgnome-keyring - PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a - - gxs { - LIBS += ../../supportlibs/pegmarkdown/lib/libpegmarkdown.a - LIBS += -lsqlite3 - } - -} - -##################################### OpenBSD ###################################### - -openbsd-* { - INCLUDEPATH *= /usr/local/include - - PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a - PRE_TARGETDEPS *= ../../openpgpsdk/src/lib/libops.a - - LIBS *= ../../libretroshare/src/lib/libretroshare.a - LIBS *= ../librssimulator/lib/librssimulator.a - LIBS *= ../../openpgpsdk/src/lib/libops.a -lbz2 - LIBS *= -lssl -lcrypto - LIBS *= -lgpgme - LIBS *= -lupnp - LIBS *= -lgnome-keyring - PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a - - gxs { - LIBS += ../../supportlibs/pegmarkdown/lib/libpegmarkdown.a - LIBS += -lsqlite3 - } - - LIBS *= -rdynamic -} - - - -############################## Common stuff ###################################### - -# On Linux systems that alredy have libssl and libcrypto it is advisable -# to rename the patched version of SSL to something like libsslxpgp.a and libcryptoxpg.a - -# ########################################### - -bitdht { - LIBS += ../../libbitdht/src/lib/libbitdht.a - PRE_TARGETDEPS *= ../../libbitdht/src/lib/libbitdht.a -} - -win32 { -# must be added after bitdht - LIBS += -lws2_32 -} - -DEPENDPATH += . \ - -INCLUDEPATH += ../../libretroshare/src/ -INCLUDEPATH += ../librssimulator/ - -SOURCES += unittests.cc \ - -################################ Serialiser ################################ -HEADERS += libretroshare/serialiser/support.h \ - libretroshare/serialiser/rstlvutil.h \ - -SOURCES += libretroshare/serialiser/rsturtleitem_test.cc \ - libretroshare/serialiser/rsbaseitem_test.cc \ - libretroshare/serialiser/rsgxsupdateitem_test.cc \ - libretroshare/serialiser/rsmsgitem_test.cc \ - libretroshare/serialiser/rsstatusitem_test.cc \ - libretroshare/serialiser/rsnxsitems_test.cc \ - libretroshare/serialiser/rsgxsiditem_test.cc \ -# libretroshare/serialiser/rsphotoitem_test.cc \ - libretroshare/serialiser/tlvbase_test2.cc \ - libretroshare/serialiser/tlvrandom_test.cc \ - libretroshare/serialiser/tlvbase_test.cc \ - libretroshare/serialiser/tlvstack_test.cc \ - libretroshare/serialiser/tlvitems_test.cc \ -# libretroshare/serialiser/rsgrouteritem_test.cc \ - libretroshare/serialiser/tlvtypes_test.cc \ - libretroshare/serialiser/tlvkey_test.cc \ - libretroshare/serialiser/support.cc \ - libretroshare/serialiser/rstlvutil.cc \ - -# Still to convert these. -# libretroshare/serialiser/rsconfigitem_test.cc \ -# libretroshare/serialiser/rsgrouteritem_test.cc \ - - -################################## GXS ##################################### - -HEADERS += libretroshare/gxs/common/data_support.h \ - -SOURCES += libretroshare/gxs/common/data_support.cc \ - -HEADERS += libretroshare/gxs/nxs_test/nxsdummyservices.h \ - libretroshare/gxs/nxs_test/nxsgrptestscenario.h \ - libretroshare/gxs/nxs_test/nxsmsgtestscenario.h \ - libretroshare/gxs/nxs_test/nxsgrpsync_test.h \ - libretroshare/gxs/nxs_test/nxsmsgsync_test.h \ - libretroshare/gxs/nxs_test/nxstesthub.h \ - libretroshare/gxs/nxs_test/nxstestscenario.h \ - libretroshare/gxs/nxs_test/nxsgrpsyncdelayed.h - -SOURCES += libretroshare/gxs/nxs_test/nxsdummyservices.cc \ - libretroshare/gxs/nxs_test/nxsgrptestscenario.cc \ - libretroshare/gxs/nxs_test/nxsmsgtestscenario.cc \ - libretroshare/gxs/nxs_test/nxstesthub.cc \ - libretroshare/gxs/nxs_test/rsgxsnetservice_test.cc \ - libretroshare/gxs/nxs_test/nxsmsgsync_test.cc \ - libretroshare/gxs/nxs_test/nxsgrpsync_test.cc \ - libretroshare/gxs/nxs_test/nxsgrpsyncdelayed.cc - -HEADERS += libretroshare/gxs/gen_exchange/genexchangetester.h \ - libretroshare/gxs/gen_exchange/gxspublishmsgtest.h \ - libretroshare/gxs/gen_exchange/genexchangetestservice.h \ - libretroshare/gxs/gen_exchange/gxspublishgrouptest.h \ - libretroshare/gxs/gen_exchange/rsdummyservices.h \ - libretroshare/gxs/gen_exchange/gxsteststats.cpp - -# libretroshare/gxs/gen_exchange/gxsmsgrelatedtest.h \ - -SOURCES += libretroshare/gxs/gen_exchange/gxspublishgrouptest.cc \ - libretroshare/gxs/gen_exchange/gxsteststats.cpp \ - libretroshare/gxs/gen_exchange/gxspublishmsgtest.cc \ - libretroshare/gxs/gen_exchange/rsdummyservices.cc \ - libretroshare/gxs/gen_exchange/rsgenexchange_test.cc \ - libretroshare/gxs/gen_exchange/genexchangetester.cc \ - libretroshare/gxs/gen_exchange/genexchangetestservice.cc \ - -SOURCES += libretroshare/gxs/security/gxssecurity_test.cc - -# libretroshare/gxs/gen_exchange/gxsmsgrelatedtest.cc \ - -HEADERS += libretroshare/gxs/data_service/rsdataservice_test.h \ - -SOURCES += libretroshare/gxs/data_service/rsdataservice_test.cc \ - libretroshare/gxs/data_service/rsgxsdata_test.cc \ - - -################################ dbase ##################################### - - -#SOURCES += libretroshare/dbase/fisavetest.cc \ -# libretroshare/dbase/fitest2.cc \ -# libretroshare/dbase/searchtest.cc \ - -# libretroshare/dbase/ficachetest.cc \ -# libretroshare/dbase/fimontest.cc \ - - -############################### services ################################### - -SOURCES += libretroshare/services/status/status_test.cc \ - -############################### gxs ######################################## - -HEADERS += libretroshare/services/gxs/rsgxstestitems.h \ - libretroshare/services/gxs/gxstestservice.h \ - libretroshare/services/gxs/GxsIsolatedServiceTester.h \ - libretroshare/services/gxs/GxsPeerNode.h \ - libretroshare/services/gxs/GxsPairServiceTester.h \ - libretroshare/services/gxs/FakePgpAuxUtils.h \ - -# libretroshare/services/gxs/RsGxsNetServiceTester.h \ - -SOURCES += libretroshare/services/gxs/rsgxstestitems.cc \ - libretroshare/services/gxs/gxstestservice.cc \ - libretroshare/services/gxs/GxsIsolatedServiceTester.cc \ - libretroshare/services/gxs/GxsPeerNode.cc \ - libretroshare/services/gxs/GxsPairServiceTester.cc \ - libretroshare/services/gxs/FakePgpAuxUtils.cc \ - libretroshare/services/gxs/nxsbasic_test.cc \ - libretroshare/services/gxs/nxspair_tests.cc \ - libretroshare/services/gxs/gxscircle_tests.cc \ - -# libretroshare/services/gxs/gxscircle_mintest.cc \ - - -# libretroshare/services/gxs/RsGxsNetServiceTester.cc \ +} + +##################################### MacOS ###################################### + +macx { + # ENABLE THIS OPTION FOR Univeral Binary BUILD. + #CONFIG += ppc x86 + #QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.4 + + CONFIG += version_detail_bash_script + LIBS += ../../libretroshare/src/lib/libretroshare.a + LIBS += ../librssimulator/lib/librssimulator.a + LIBS += ../../openpgpsdk/src/lib/libops.a -lbz2 + LIBS += -lssl -lcrypto -lz + #LIBS += -lssl -lcrypto -lz -lgpgme -lgpg-error -lassuan + for(lib, LIB_DIR):exists($$lib/libminiupnpc.a){ LIBS += $$lib/libminiupnpc.a} + LIBS += -framework CoreFoundation + LIBS += -framework Security + + + for(lib, LIB_DIR):LIBS += -L"$$lib" + for(bin, BIN_DIR):LIBS += -L"$$bin" + + DEPENDPATH += . $$INC_DIR + INCLUDEPATH += . $$INC_DIR + + #LIBS += ../../supportlibs/pegmarkdown/lib/libpegmarkdown.a + + # We need a explicit path here, to force using the home version of sqlite3 that really encrypts the database. + LIBS += /usr/local/lib/libsqlcipher.a + #LIBS += -lsqlite3 + + #DEFINES* = MAC_IDLE # for idle feature + CONFIG -= uitools +} + +##################################### FreeBSD ###################################### + +freebsd-* { + INCLUDEPATH *= /usr/local/include/gpgme + LIBS *= ../../libretroshare/src/lib/libretroshare.a + LIBS *= ../librssimulator/lib/librssimulator.a + LIBS *= -lssl + LIBS *= -lgpgme + LIBS *= -lupnp + LIBS *= -lgnome-keyring + PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a + + gxs { + LIBS += ../../supportlibs/pegmarkdown/lib/libpegmarkdown.a + LIBS += -lsqlite3 + } + +} + +##################################### OpenBSD ###################################### + +openbsd-* { + INCLUDEPATH *= /usr/local/include + + PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a + PRE_TARGETDEPS *= ../../openpgpsdk/src/lib/libops.a + + LIBS *= ../../libretroshare/src/lib/libretroshare.a + LIBS *= ../librssimulator/lib/librssimulator.a + LIBS *= ../../openpgpsdk/src/lib/libops.a -lbz2 + LIBS *= -lssl -lcrypto + LIBS *= -lgpgme + LIBS *= -lupnp + LIBS *= -lgnome-keyring + PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a + + gxs { + LIBS += ../../supportlibs/pegmarkdown/lib/libpegmarkdown.a + LIBS += -lsqlite3 + } + + LIBS *= -rdynamic +} + + + +############################## Common stuff ###################################### + +# On Linux systems that alredy have libssl and libcrypto it is advisable +# to rename the patched version of SSL to something like libsslxpgp.a and libcryptoxpg.a + +# ########################################### + +bitdht { + LIBS += ../../libbitdht/src/lib/libbitdht.a + PRE_TARGETDEPS *= ../../libbitdht/src/lib/libbitdht.a +} + +win32 { +# must be added after bitdht + LIBS += -lws2_32 +} + +DEPENDPATH += . \ + +INCLUDEPATH += ../../libretroshare/src/ +INCLUDEPATH += ../librssimulator/ + +SOURCES += unittests.cc \ + +################################ Serialiser ################################ +HEADERS += libretroshare/serialiser/support.h \ + libretroshare/serialiser/rstlvutil.h \ + +SOURCES += libretroshare/serialiser/rsturtleitem_test.cc \ + libretroshare/serialiser/rsbaseitem_test.cc \ + libretroshare/serialiser/rsgxsupdateitem_test.cc \ + libretroshare/serialiser/rsmsgitem_test.cc \ + libretroshare/serialiser/rsstatusitem_test.cc \ + libretroshare/serialiser/rsnxsitems_test.cc \ + libretroshare/serialiser/rsgxsiditem_test.cc \ +# libretroshare/serialiser/rsphotoitem_test.cc \ + libretroshare/serialiser/tlvbase_test2.cc \ + libretroshare/serialiser/tlvrandom_test.cc \ + libretroshare/serialiser/tlvbase_test.cc \ + libretroshare/serialiser/tlvstack_test.cc \ + libretroshare/serialiser/tlvitems_test.cc \ +# libretroshare/serialiser/rsgrouteritem_test.cc \ + libretroshare/serialiser/tlvtypes_test.cc \ + libretroshare/serialiser/tlvkey_test.cc \ + libretroshare/serialiser/support.cc \ + libretroshare/serialiser/rstlvutil.cc \ + +# Still to convert these. +# libretroshare/serialiser/rsconfigitem_test.cc \ +# libretroshare/serialiser/rsgrouteritem_test.cc \ + + +################################## GXS ##################################### + +HEADERS += libretroshare/gxs/common/data_support.h \ + +SOURCES += libretroshare/gxs/common/data_support.cc \ + +HEADERS += libretroshare/gxs/nxs_test/nxsdummyservices.h \ + libretroshare/gxs/nxs_test/nxsgrptestscenario.h \ + libretroshare/gxs/nxs_test/nxsmsgtestscenario.h \ + libretroshare/gxs/nxs_test/nxsgrpsync_test.h \ + libretroshare/gxs/nxs_test/nxsmsgsync_test.h \ + libretroshare/gxs/nxs_test/nxstesthub.h \ + libretroshare/gxs/nxs_test/nxstestscenario.h \ + libretroshare/gxs/nxs_test/nxsgrpsyncdelayed.h + +SOURCES += libretroshare/gxs/nxs_test/nxsdummyservices.cc \ + libretroshare/gxs/nxs_test/nxsgrptestscenario.cc \ + libretroshare/gxs/nxs_test/nxsmsgtestscenario.cc \ + libretroshare/gxs/nxs_test/nxstesthub.cc \ + libretroshare/gxs/nxs_test/rsgxsnetservice_test.cc \ + libretroshare/gxs/nxs_test/nxsmsgsync_test.cc \ + libretroshare/gxs/nxs_test/nxsgrpsync_test.cc \ + libretroshare/gxs/nxs_test/nxsgrpsyncdelayed.cc + +HEADERS += libretroshare/gxs/gen_exchange/genexchangetester.h \ + libretroshare/gxs/gen_exchange/gxspublishmsgtest.h \ + libretroshare/gxs/gen_exchange/genexchangetestservice.h \ + libretroshare/gxs/gen_exchange/gxspublishgrouptest.h \ + libretroshare/gxs/gen_exchange/rsdummyservices.h \ + libretroshare/gxs/gen_exchange/gxsteststats.cpp + +# libretroshare/gxs/gen_exchange/gxsmsgrelatedtest.h \ + +SOURCES += libretroshare/gxs/gen_exchange/gxspublishgrouptest.cc \ + libretroshare/gxs/gen_exchange/gxsteststats.cpp \ + libretroshare/gxs/gen_exchange/gxspublishmsgtest.cc \ + libretroshare/gxs/gen_exchange/rsdummyservices.cc \ + libretroshare/gxs/gen_exchange/rsgenexchange_test.cc \ + libretroshare/gxs/gen_exchange/genexchangetester.cc \ + libretroshare/gxs/gen_exchange/genexchangetestservice.cc \ + +SOURCES += libretroshare/gxs/security/gxssecurity_test.cc + +# libretroshare/gxs/gen_exchange/gxsmsgrelatedtest.cc \ + +HEADERS += libretroshare/gxs/data_service/rsdataservice_test.h \ + +SOURCES += libretroshare/gxs/data_service/rsdataservice_test.cc \ + libretroshare/gxs/data_service/rsgxsdata_test.cc \ + + +################################ dbase ##################################### + + +#SOURCES += libretroshare/dbase/fisavetest.cc \ +# libretroshare/dbase/fitest2.cc \ +# libretroshare/dbase/searchtest.cc \ + +# libretroshare/dbase/ficachetest.cc \ +# libretroshare/dbase/fimontest.cc \ + + +############################### services ################################### + +SOURCES += libretroshare/services/status/status_test.cc \ + +############################### gxs ######################################## + +HEADERS += libretroshare/services/gxs/rsgxstestitems.h \ + libretroshare/services/gxs/gxstestservice.h \ + libretroshare/services/gxs/GxsIsolatedServiceTester.h \ + libretroshare/services/gxs/GxsPeerNode.h \ + libretroshare/services/gxs/GxsPairServiceTester.h \ + libretroshare/services/gxs/FakePgpAuxUtils.h \ + +# libretroshare/services/gxs/RsGxsNetServiceTester.h \ + +SOURCES += libretroshare/services/gxs/rsgxstestitems.cc \ + libretroshare/services/gxs/gxstestservice.cc \ + libretroshare/services/gxs/GxsIsolatedServiceTester.cc \ + libretroshare/services/gxs/GxsPeerNode.cc \ + libretroshare/services/gxs/GxsPairServiceTester.cc \ + libretroshare/services/gxs/FakePgpAuxUtils.cc \ + libretroshare/services/gxs/nxsbasic_test.cc \ + libretroshare/services/gxs/nxspair_tests.cc \ + libretroshare/services/gxs/gxscircle_tests.cc \ + +# libretroshare/services/gxs/gxscircle_mintest.cc \ + + +# libretroshare/services/gxs/RsGxsNetServiceTester.cc \ From 29b5bfe04911561680a720a70097048fc063e15b Mon Sep 17 00:00:00 2001 From: mr-alice Date: Thu, 3 Nov 2016 08:50:13 +0100 Subject: [PATCH 33/52] attempt to fixed leading tabs --- libretroshare/src/ft/ftserver.cc | 1732 +++++++++++++++--------------- 1 file changed, 866 insertions(+), 866 deletions(-) diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 3ebc0bc18..f8f6821ae 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -62,15 +62,15 @@ const int ftserverzone = 29539; static const time_t FILE_TRANSFER_LOW_PRIORITY_TASKS_PERIOD = 5 ; // low priority tasks handling every 5 seconds - /* Setup */ +/* Setup */ ftServer::ftServer(p3PeerMgr *pm, p3ServiceControl *sc) - : p3Service(), - mPeerMgr(pm), mServiceCtrl(sc), - mFileDatabase(NULL), - mFtController(NULL), mFtExtra(NULL), - mFtDataplex(NULL), mFtSearch(NULL), srvMutex("ftServer") + : p3Service(), + mPeerMgr(pm), mServiceCtrl(sc), + mFileDatabase(NULL), + mFtController(NULL), mFtExtra(NULL), + mFtDataplex(NULL), mFtSearch(NULL), srvMutex("ftServer") { - addSerialType(new RsFileTransferSerialiser()) ; + addSerialType(new RsFileTransferSerialiser()) ; } const std::string FILE_TRANSFER_APP_NAME = "ft"; @@ -81,141 +81,141 @@ const uint16_t FILE_TRANSFER_MIN_MINOR_VERSION = 0; RsServiceInfo ftServer::getServiceInfo() { - return RsServiceInfo(RS_SERVICE_TYPE_FILE_TRANSFER, - FILE_TRANSFER_APP_NAME, - FILE_TRANSFER_APP_MAJOR_VERSION, - FILE_TRANSFER_APP_MINOR_VERSION, - FILE_TRANSFER_MIN_MAJOR_VERSION, - FILE_TRANSFER_MIN_MINOR_VERSION); + return RsServiceInfo(RS_SERVICE_TYPE_FILE_TRANSFER, + FILE_TRANSFER_APP_NAME, + FILE_TRANSFER_APP_MAJOR_VERSION, + FILE_TRANSFER_APP_MINOR_VERSION, + FILE_TRANSFER_MIN_MAJOR_VERSION, + FILE_TRANSFER_MIN_MINOR_VERSION); } void ftServer::setConfigDirectory(std::string path) { - mConfigPath = path; + mConfigPath = path; - /* Must update the sub classes ... if they exist - * TODO. - */ + /* Must update the sub classes ... if they exist + * TODO. + */ - std::string basecachedir = mConfigPath + "/cache"; - std::string localcachedir = mConfigPath + "/cache/local"; - std::string remotecachedir = mConfigPath + "/cache/remote"; + std::string basecachedir = mConfigPath + "/cache"; + std::string localcachedir = mConfigPath + "/cache/local"; + std::string remotecachedir = mConfigPath + "/cache/remote"; - RsDirUtil::checkCreateDirectory(basecachedir) ; - RsDirUtil::checkCreateDirectory(localcachedir) ; - RsDirUtil::checkCreateDirectory(remotecachedir) ; + RsDirUtil::checkCreateDirectory(basecachedir) ; + RsDirUtil::checkCreateDirectory(localcachedir) ; + RsDirUtil::checkCreateDirectory(remotecachedir) ; } - /* Control Interface */ +/* Control Interface */ - /* add Config Items (Extra, Controller) */ +/* add Config Items (Extra, Controller) */ void ftServer::addConfigComponents(p3ConfigMgr */*mgr*/) { - /* NOT SURE ABOUT THIS ONE */ + /* NOT SURE ABOUT THIS ONE */ } const RsPeerId& ftServer::OwnId() { - static RsPeerId null_id ; + static RsPeerId null_id ; - if (mServiceCtrl) - return mServiceCtrl->getOwnId(); - else - return null_id ; + if (mServiceCtrl) + return mServiceCtrl->getOwnId(); + else + return null_id ; } - /* Final Setup (once everything is assigned) */ +/* Final Setup (once everything is assigned) */ void ftServer::SetupFtServer() { - /* setup FiStore/Monitor */ - std::string localcachedir = mConfigPath + "/cache/local"; - std::string remotecachedir = mConfigPath + "/cache/remote"; - RsPeerId ownId = mServiceCtrl->getOwnId(); + /* setup FiStore/Monitor */ + std::string localcachedir = mConfigPath + "/cache/local"; + std::string remotecachedir = mConfigPath + "/cache/remote"; + RsPeerId ownId = mServiceCtrl->getOwnId(); - /* search/extras List */ - mFtExtra = new ftExtraList(); - mFtSearch = new ftFileSearch(); + /* search/extras List */ + mFtExtra = new ftExtraList(); + mFtSearch = new ftFileSearch(); - /* Transport */ - mFtDataplex = new ftDataMultiplex(ownId, this, mFtSearch); + /* Transport */ + mFtDataplex = new ftDataMultiplex(ownId, this, mFtSearch); - /* make Controller */ - mFtController = new ftController(mFtDataplex, mServiceCtrl, getServiceInfo().mServiceType); - mFtController -> setFtSearchNExtra(mFtSearch, mFtExtra); - std::string tmppath = "."; - mFtController->setPartialsDirectory(tmppath); - mFtController->setDownloadDirectory(tmppath); + /* make Controller */ + mFtController = new ftController(mFtDataplex, mServiceCtrl, getServiceInfo().mServiceType); + mFtController -> setFtSearchNExtra(mFtSearch, mFtExtra); + std::string tmppath = "."; + mFtController->setPartialsDirectory(tmppath); + mFtController->setDownloadDirectory(tmppath); - /* complete search setup */ - mFtSearch->addSearchMode(mFtExtra, RS_FILE_HINTS_EXTRA); + /* complete search setup */ + mFtSearch->addSearchMode(mFtExtra, RS_FILE_HINTS_EXTRA); - mServiceCtrl->registerServiceMonitor(mFtController, getServiceInfo().mServiceType); + mServiceCtrl->registerServiceMonitor(mFtController, getServiceInfo().mServiceType); - return; + return; } void ftServer::connectToFileDatabase(p3FileDatabase *fdb) { - mFileDatabase = fdb ; - mFtSearch->addSearchMode(fdb, RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_REMOTE); + mFileDatabase = fdb ; + mFtSearch->addSearchMode(fdb, RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_REMOTE); } void ftServer::connectToTurtleRouter(p3turtle *fts) { - mTurtleRouter = fts ; + mTurtleRouter = fts ; - mFtController->setTurtleRouter(fts) ; - mFtController->setFtServer(this) ; + mFtController->setTurtleRouter(fts) ; + mFtController->setFtServer(this) ; - mTurtleRouter->registerTunnelService(this) ; + mTurtleRouter->registerTunnelService(this) ; } void ftServer::StartupThreads() { - /* start up order - important for dependencies */ + /* start up order - important for dependencies */ - /* self contained threads */ - /* startup ExtraList Thread */ - mFtExtra->start("ft extra lst"); + /* self contained threads */ + /* startup ExtraList Thread */ + mFtExtra->start("ft extra lst"); - /* startup Monitor Thread */ - /* startup the FileMonitor (after cache load) */ - /* start it up */ - mFileDatabase->startThreads(); + /* startup Monitor Thread */ + /* startup the FileMonitor (after cache load) */ + /* start it up */ + mFileDatabase->startThreads(); - /* Controller thread */ - mFtController->start("ft ctrl"); + /* Controller thread */ + mFtController->start("ft ctrl"); - /* Dataplex */ - mFtDataplex->start("ft dataplex"); + /* Dataplex */ + mFtDataplex->start("ft dataplex"); } void ftServer::StopThreads() { - /* stop Dataplex */ - mFtDataplex->join(); + /* stop Dataplex */ + mFtDataplex->join(); - /* stop Controller thread */ - mFtController->join(); + /* stop Controller thread */ + mFtController->join(); - /* self contained threads */ - /* stop ExtraList Thread */ - mFtExtra->join(); + /* self contained threads */ + /* stop ExtraList Thread */ + mFtExtra->join(); - delete (mFtDataplex); - mFtDataplex = NULL; + delete (mFtDataplex); + mFtDataplex = NULL; - delete (mFtController); - mFtController = NULL; + delete (mFtController); + mFtController = NULL; - delete (mFtExtra); - mFtExtra = NULL; + delete (mFtExtra); + mFtExtra = NULL; - /* stop Monitor Thread */ - mFileDatabase->stopThreads(); - delete mFileDatabase; - mFileDatabase = NULL ; + /* stop Monitor Thread */ + mFileDatabase->stopThreads(); + delete mFileDatabase; + mFileDatabase = NULL ; } /***************************************************************/ @@ -228,184 +228,184 @@ void ftServer::StopThreads() bool ftServer::ResumeTransfers() { - mFtController->activate(); + mFtController->activate(); - return true; + return true; } bool ftServer::getFileData(const RsFileHash& hash, uint64_t offset, uint32_t& requested_size,uint8_t *data) { - return mFtDataplex->getFileData(hash, offset, requested_size,data); + return mFtDataplex->getFileData(hash, offset, requested_size,data); } bool ftServer::alreadyHaveFile(const RsFileHash& hash, FileInfo &info) { - return mFileDatabase->search(hash, RS_FILE_HINTS_LOCAL, info); + return mFileDatabase->search(hash, RS_FILE_HINTS_LOCAL, info); } bool ftServer::FileRequest(const std::string& fname, const RsFileHash& hash, uint64_t size, const std::string& dest, TransferRequestFlags flags, const std::list& srcIds) { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "Requesting " << fname << std::endl ; + FTSERVER_DEBUG() << "Requesting " << fname << std::endl ; #endif - if(!mFtController->FileRequest(fname, hash, size, dest, flags, srcIds)) - return false ; + if(!mFtController->FileRequest(fname, hash, size, dest, flags, srcIds)) + return false ; - return true ; + return true ; } bool ftServer::activateTunnels(const RsFileHash& hash,uint32_t encryption_policy,TransferRequestFlags flags,bool onoff) { - RsFileHash hash_of_hash ; + RsFileHash hash_of_hash ; - encryptHash(hash,hash_of_hash) ; - mEncryptedHashes.insert(std::make_pair(hash_of_hash,hash)) ; + encryptHash(hash,hash_of_hash) ; + mEncryptedHashes.insert(std::make_pair(hash_of_hash,hash)) ; - if(onoff) - { + if(onoff) + { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "Activating tunnels for hash " << hash << std::endl; + FTSERVER_DEBUG() << "Activating tunnels for hash " << hash << std::endl; #endif - if(flags & RS_FILE_REQ_ENCRYPTED) - { + if(flags & RS_FILE_REQ_ENCRYPTED) + { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << " flags require end-to-end encryption. Requesting hash of hash " << hash_of_hash << std::endl; + FTSERVER_DEBUG() << " flags require end-to-end encryption. Requesting hash of hash " << hash_of_hash << std::endl; #endif - mTurtleRouter->monitorTunnels(hash_of_hash,this,true) ; - } - if((flags & RS_FILE_REQ_UNENCRYPTED) && (encryption_policy != RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT)) - { + mTurtleRouter->monitorTunnels(hash_of_hash,this,true) ; + } + if((flags & RS_FILE_REQ_UNENCRYPTED) && (encryption_policy != RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT)) + { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << " flags require no end-to-end encryption. Requesting hash " << hash << std::endl; + FTSERVER_DEBUG() << " flags require no end-to-end encryption. Requesting hash " << hash << std::endl; #endif - mTurtleRouter->monitorTunnels(hash,this,true) ; - } - } - else - { - mTurtleRouter->stopMonitoringTunnels(hash_of_hash); - mTurtleRouter->stopMonitoringTunnels(hash); - } - return true ; + mTurtleRouter->monitorTunnels(hash,this,true) ; + } + } + else + { + mTurtleRouter->stopMonitoringTunnels(hash_of_hash); + mTurtleRouter->stopMonitoringTunnels(hash); + } + return true ; } bool ftServer::setDestinationName(const RsFileHash& hash,const std::string& name) { - return mFtController->setDestinationName(hash,name); + return mFtController->setDestinationName(hash,name); } bool ftServer::setDestinationDirectory(const RsFileHash& hash,const std::string& directory) { - return mFtController->setDestinationDirectory(hash,directory); + return mFtController->setDestinationDirectory(hash,directory); } bool ftServer::setChunkStrategy(const RsFileHash& hash,FileChunksInfo::ChunkStrategy s) { - return mFtController->setChunkStrategy(hash,s); + return mFtController->setChunkStrategy(hash,s); } uint32_t ftServer::freeDiskSpaceLimit()const { - return mFtController->freeDiskSpaceLimit() ; + return mFtController->freeDiskSpaceLimit() ; } void ftServer::setFreeDiskSpaceLimit(uint32_t s) { - mFtController->setFreeDiskSpaceLimit(s) ; + mFtController->setFreeDiskSpaceLimit(s) ; } void ftServer::setDefaultChunkStrategy(FileChunksInfo::ChunkStrategy s) { - mFtController->setDefaultChunkStrategy(s) ; + mFtController->setDefaultChunkStrategy(s) ; } uint32_t ftServer::defaultEncryptionPolicy() { - return mFtController->defaultEncryptionPolicy() ; + return mFtController->defaultEncryptionPolicy() ; } void ftServer::setDefaultEncryptionPolicy(uint32_t s) { - mFtController->setDefaultEncryptionPolicy(s) ; + mFtController->setDefaultEncryptionPolicy(s) ; } FileChunksInfo::ChunkStrategy ftServer::defaultChunkStrategy() { - return mFtController->defaultChunkStrategy() ; + return mFtController->defaultChunkStrategy() ; } bool ftServer::FileCancel(const RsFileHash& hash) { - // Remove from both queue and ftController, by default. - // - mFtController->FileCancel(hash); + // Remove from both queue and ftController, by default. + // + mFtController->FileCancel(hash); - return true ; + return true ; } bool ftServer::FileControl(const RsFileHash& hash, uint32_t flags) { - return mFtController->FileControl(hash, flags); + return mFtController->FileControl(hash, flags); } bool ftServer::FileClearCompleted() { - return mFtController->FileClearCompleted(); + return mFtController->FileClearCompleted(); } void ftServer::setQueueSize(uint32_t s) { - mFtController->setQueueSize(s) ; + mFtController->setQueueSize(s) ; } uint32_t ftServer::getQueueSize() { - return mFtController->getQueueSize() ; + return mFtController->getQueueSize() ; } - /* Control of Downloads Priority. */ +/* Control of Downloads Priority. */ bool ftServer::changeQueuePosition(const RsFileHash& hash, QueueMove mv) { - mFtController->moveInQueue(hash,mv) ; - return true ; + mFtController->moveInQueue(hash,mv) ; + return true ; } bool ftServer::changeDownloadSpeed(const RsFileHash& hash, int speed) { - mFtController->setPriority(hash, (DwlSpeed)speed); - return true ; + mFtController->setPriority(hash, (DwlSpeed)speed); + return true ; } bool ftServer::getDownloadSpeed(const RsFileHash& hash, int & speed) { - DwlSpeed _speed; - int ret = mFtController->getPriority(hash, _speed); - if (ret) - speed = _speed; + DwlSpeed _speed; + int ret = mFtController->getPriority(hash, _speed); + if (ret) + speed = _speed; - return ret; + return ret; } bool ftServer::clearDownload(const RsFileHash& /*hash*/) { - return true ; + return true ; } bool ftServer::FileDownloadChunksDetails(const RsFileHash& hash,FileChunksInfo& info) { - return mFtController->getFileDownloadChunksDetails(hash,info); + return mFtController->getFileDownloadChunksDetails(hash,info); } void ftServer::requestDirUpdate(void *ref) { - mFileDatabase->requestDirUpdate(ref) ; + mFileDatabase->requestDirUpdate(ref) ; } - /* Directory Handling */ +/* Directory Handling */ void ftServer::setDownloadDirectory(std::string path) { - mFtController->setDownloadDirectory(path); + mFtController->setDownloadDirectory(path); } std::string ftServer::getDownloadDirectory() { - return mFtController->getDownloadDirectory(); + return mFtController->getDownloadDirectory(); } void ftServer::setPartialsDirectory(std::string path) { - mFtController->setPartialsDirectory(path); + mFtController->setPartialsDirectory(path); } std::string ftServer::getPartialsDirectory() { - return mFtController->getPartialsDirectory(); + return mFtController->getPartialsDirectory(); } /***************************************************************/ @@ -414,217 +414,217 @@ std::string ftServer::getPartialsDirectory() bool ftServer::copyFile(const std::string& source, const std::string& dest) { - return mFtController->copyFile(source, dest); + return mFtController->copyFile(source, dest); } void ftServer::FileDownloads(std::list &hashs) { - mFtController->FileDownloads(hashs); + mFtController->FileDownloads(hashs); } bool ftServer::FileUploadChunksDetails(const RsFileHash& hash,const RsPeerId& peer_id,CompressedChunkMap& cmap) { - return mFtDataplex->getClientChunkMap(hash,peer_id,cmap); + return mFtDataplex->getClientChunkMap(hash,peer_id,cmap); } bool ftServer::FileUploads(std::list &hashs) { - return mFtDataplex->FileUploads(hashs); + return mFtDataplex->FileUploads(hashs); } bool ftServer::FileDetails(const RsFileHash &hash, FileSearchFlags hintflags, FileInfo &info) { - if (hintflags & RS_FILE_HINTS_DOWNLOAD) - if(mFtController->FileDetails(hash, info)) - return true ; + if (hintflags & RS_FILE_HINTS_DOWNLOAD) + if(mFtController->FileDetails(hash, info)) + return true ; - if(hintflags & RS_FILE_HINTS_UPLOAD) - if(mFtDataplex->FileDetails(hash, hintflags, info)) - { - // We also check if the file is a DL as well. In such a case we use - // the DL as the file name, to replace the hash. If the file is a cache - // file, we skip the call to fileDetails() for efficiency reasons. - // - FileInfo info2 ; - if(mFtController->FileDetails(hash, info2)) - info.fname = info2.fname ; + if(hintflags & RS_FILE_HINTS_UPLOAD) + if(mFtDataplex->FileDetails(hash, hintflags, info)) + { + // We also check if the file is a DL as well. In such a case we use + // the DL as the file name, to replace the hash. If the file is a cache + // file, we skip the call to fileDetails() for efficiency reasons. + // + FileInfo info2 ; + if(mFtController->FileDetails(hash, info2)) + info.fname = info2.fname ; - return true ; - } + return true ; + } - if(hintflags & ~(RS_FILE_HINTS_UPLOAD | RS_FILE_HINTS_DOWNLOAD)) - if(mFtSearch->search(hash, hintflags, info)) - return true ; + if(hintflags & ~(RS_FILE_HINTS_UPLOAD | RS_FILE_HINTS_DOWNLOAD)) + if(mFtSearch->search(hash, hintflags, info)) + return true ; - return false; + return false; } RsTurtleGenericTunnelItem *ftServer::deserialiseItem(void *data,uint32_t size) const { - uint32_t rstype = getRsItemId(data); + uint32_t rstype = getRsItemId(data); #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "p3turtle: deserialising packet: " << std::endl ; + FTSERVER_DEBUG() << "p3turtle: deserialising packet: " << std::endl ; #endif - if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_TURTLE != getRsItemService(rstype))) - { - FTSERVER_ERROR() << " Wrong type !!" << std::endl ; - return NULL; /* wrong type */ - } + if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_TURTLE != getRsItemService(rstype))) + { + FTSERVER_ERROR() << " Wrong type !!" << std::endl ; + return NULL; /* wrong type */ + } - try - { - switch(getRsItemSubType(rstype)) - { - case RS_TURTLE_SUBTYPE_FILE_REQUEST : return new RsTurtleFileRequestItem(data,size) ; - case RS_TURTLE_SUBTYPE_FILE_DATA : return new RsTurtleFileDataItem(data,size) ; - case RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST : return new RsTurtleFileMapRequestItem(data,size) ; - case RS_TURTLE_SUBTYPE_FILE_MAP : return new RsTurtleFileMapItem(data,size) ; - case RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST : return new RsTurtleChunkCrcRequestItem(data,size) ; - case RS_TURTLE_SUBTYPE_CHUNK_CRC : return new RsTurtleChunkCrcItem(data,size) ; + try + { + switch(getRsItemSubType(rstype)) + { + case RS_TURTLE_SUBTYPE_FILE_REQUEST : return new RsTurtleFileRequestItem(data,size) ; + case RS_TURTLE_SUBTYPE_FILE_DATA : return new RsTurtleFileDataItem(data,size) ; + case RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST : return new RsTurtleFileMapRequestItem(data,size) ; + case RS_TURTLE_SUBTYPE_FILE_MAP : return new RsTurtleFileMapItem(data,size) ; + case RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST : return new RsTurtleChunkCrcRequestItem(data,size) ; + case RS_TURTLE_SUBTYPE_CHUNK_CRC : return new RsTurtleChunkCrcItem(data,size) ; - default: - return NULL ; - } - } - catch(std::exception& e) - { - FTSERVER_ERROR() << "(EE) deserialisation error in " << __PRETTY_FUNCTION__ << ": " << e.what() << std::endl; + default: + return NULL ; + } + } + catch(std::exception& e) + { + FTSERVER_ERROR() << "(EE) deserialisation error in " << __PRETTY_FUNCTION__ << ": " << e.what() << std::endl; - return NULL ; - } + return NULL ; + } } bool ftServer::isEncryptedSource(const RsPeerId& virtual_peer_id) { - RS_STACK_MUTEX(srvMutex) ; + RS_STACK_MUTEX(srvMutex) ; - return mEncryptedPeerIds.find(virtual_peer_id) != mEncryptedPeerIds.end(); + return mEncryptedPeerIds.find(virtual_peer_id) != mEncryptedPeerIds.end(); } void ftServer::addVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id,RsTurtleGenericTunnelItem::Direction dir) { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "adding virtual peer. Direction=" << dir << ", hash=" << hash << ", vpid=" << virtual_peer_id << std::endl; + FTSERVER_DEBUG() << "adding virtual peer. Direction=" << dir << ", hash=" << hash << ", vpid=" << virtual_peer_id << std::endl; #endif - RsFileHash real_hash ; + RsFileHash real_hash ; - { - if(findRealHash(hash,real_hash)) - { - RS_STACK_MUTEX(srvMutex) ; - mEncryptedPeerIds[virtual_peer_id] = hash ; - } - else - real_hash = hash; - } + { + if(findRealHash(hash,real_hash)) + { + RS_STACK_MUTEX(srvMutex) ; + mEncryptedPeerIds[virtual_peer_id] = hash ; + } + else + real_hash = hash; + } - if(dir == RsTurtleGenericTunnelItem::DIRECTION_SERVER) - { + if(dir == RsTurtleGenericTunnelItem::DIRECTION_SERVER) + { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << " direction is SERVER. Adding file source for end-to-end encrypted tunnel for real hash " << real_hash << ", virtual peer id = " << virtual_peer_id << std::endl; + FTSERVER_DEBUG() << " direction is SERVER. Adding file source for end-to-end encrypted tunnel for real hash " << real_hash << ", virtual peer id = " << virtual_peer_id << std::endl; #endif - mFtController->addFileSource(real_hash,virtual_peer_id) ; - } + mFtController->addFileSource(real_hash,virtual_peer_id) ; + } } void ftServer::removeVirtualPeer(const TurtleFileHash& hash,const TurtleVirtualPeerId& virtual_peer_id) { - RsFileHash real_hash ; - if(findRealHash(hash,real_hash)) - mFtController->removeFileSource(real_hash,virtual_peer_id) ; - else - mFtController->removeFileSource(hash,virtual_peer_id) ; + RsFileHash real_hash ; + if(findRealHash(hash,real_hash)) + mFtController->removeFileSource(real_hash,virtual_peer_id) ; + else + mFtController->removeFileSource(hash,virtual_peer_id) ; - RS_STACK_MUTEX(srvMutex) ; - mEncryptedPeerIds.erase(virtual_peer_id) ; + RS_STACK_MUTEX(srvMutex) ; + mEncryptedPeerIds.erase(virtual_peer_id) ; } bool ftServer::handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_id) { - FileInfo info ; - RsFileHash real_hash ; - bool found = false ; + FileInfo info ; + RsFileHash real_hash ; + bool found = false ; - if(FileDetails(hash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY, info)) - { - if(info.transfer_info_flags & RS_FILE_REQ_ENCRYPTED) - { + if(FileDetails(hash, RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_LOCAL | RS_FILE_HINTS_EXTRA | RS_FILE_HINTS_SPEC_ONLY, info)) + { + if(info.transfer_info_flags & RS_FILE_REQ_ENCRYPTED) + { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "handleTunnelRequest: openning encrypted FT tunnel for H(H(F))=" << hash << " and H(F)=" << info.hash << std::endl; + FTSERVER_DEBUG() << "handleTunnelRequest: openning encrypted FT tunnel for H(H(F))=" << hash << " and H(F)=" << info.hash << std::endl; #endif - RS_STACK_MUTEX(srvMutex) ; - mEncryptedHashes[hash] = info.hash; + RS_STACK_MUTEX(srvMutex) ; + mEncryptedHashes[hash] = info.hash; - real_hash = info.hash ; - } - else - real_hash = hash ; + real_hash = info.hash ; + } + else + real_hash = hash ; - found = true ; - } - else // try to see if we're already swarming the file - { - { - RS_STACK_MUTEX(srvMutex) ; - std::map::const_iterator it = mEncryptedHashes.find(hash) ; + found = true ; + } + else // try to see if we're already swarming the file + { + { + RS_STACK_MUTEX(srvMutex) ; + std::map::const_iterator it = mEncryptedHashes.find(hash) ; - if(it != mEncryptedHashes.end()) - real_hash = it->second ; - else - real_hash = hash ; - } + if(it != mEncryptedHashes.end()) + real_hash = it->second ; + else + real_hash = hash ; + } - if(FileDetails(real_hash,RS_FILE_HINTS_DOWNLOAD,info)) - { - // This file is currently being downloaded. Let's look if we already have a chunk or not. If not, no need to - // share the file! + if(FileDetails(real_hash,RS_FILE_HINTS_DOWNLOAD,info)) + { + // This file is currently being downloaded. Let's look if we already have a chunk or not. If not, no need to + // share the file! - FileChunksInfo info2 ; - if(rsFiles->FileDownloadChunksDetails(hash, info2)) - for(uint32_t i=0;iFileDownloadChunksDetails(hash, info2)) + for(uint32_t i=0;idefaultEncryptionPolicy() == RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT && hash == real_hash) - { - std::cerr << "(WW) rejecting file transfer for hash " << hash << " because the hash is not encrypted and encryption policy requires it." << std::endl; - return false ; - } + if(mFtController->defaultEncryptionPolicy() == RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT && hash == real_hash) + { + std::cerr << "(WW) rejecting file transfer for hash " << hash << " because the hash is not encrypted and encryption policy requires it." << std::endl; + return false ; + } #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "ftServer: performing local hash search for hash " << hash << std::endl; + FTSERVER_DEBUG() << "ftServer: performing local hash search for hash " << hash << std::endl; - if(found) - { - FTSERVER_DEBUG() << "Found hash: " << std::endl; - FTSERVER_DEBUG() << " hash = " << real_hash << std::endl; - FTSERVER_DEBUG() << " peer = " << peer_id << std::endl; - FTSERVER_DEBUG() << " flags = " << info.storage_permission_flags << std::endl; - FTSERVER_DEBUG() << " groups= " ; - for(std::list::const_iterator it(info.parent_groups.begin());it!=info.parent_groups.end();++it) - FTSERVER_DEBUG() << (*it) << ", " ; - FTSERVER_DEBUG() << std::endl; - FTSERVER_DEBUG() << " clear = " << rsPeers->computePeerPermissionFlags(peer_id,info.storage_permission_flags,info.parent_groups) << std::endl; - } + if(found) + { + FTSERVER_DEBUG() << "Found hash: " << std::endl; + FTSERVER_DEBUG() << " hash = " << real_hash << std::endl; + FTSERVER_DEBUG() << " peer = " << peer_id << std::endl; + FTSERVER_DEBUG() << " flags = " << info.storage_permission_flags << std::endl; + FTSERVER_DEBUG() << " groups= " ; + for(std::list::const_iterator it(info.parent_groups.begin());it!=info.parent_groups.end();++it) + FTSERVER_DEBUG() << (*it) << ", " ; + FTSERVER_DEBUG() << std::endl; + FTSERVER_DEBUG() << " clear = " << rsPeers->computePeerPermissionFlags(peer_id,info.storage_permission_flags,info.parent_groups) << std::endl; + } #endif - // The call to computeHashPeerClearance() return a combination of RS_FILE_HINTS_NETWORK_WIDE and RS_FILE_HINTS_BROWSABLE - // This is an additional computation cost, but the way it's written here, it's only called when res is true. - // - found = found && (RS_FILE_HINTS_NETWORK_WIDE & rsPeers->computePeerPermissionFlags(peer_id,info.storage_permission_flags,info.parent_groups)) ; + // The call to computeHashPeerClearance() return a combination of RS_FILE_HINTS_NETWORK_WIDE and RS_FILE_HINTS_BROWSABLE + // This is an additional computation cost, but the way it's written here, it's only called when res is true. + // + found = found && (RS_FILE_HINTS_NETWORK_WIDE & rsPeers->computePeerPermissionFlags(peer_id,info.storage_permission_flags,info.parent_groups)) ; - return found ; + return found ; } /***************************************************************/ @@ -633,27 +633,27 @@ bool ftServer::handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_i bool ftServer::ExtraFileAdd(std::string fname, const RsFileHash& hash, uint64_t size, uint32_t period, TransferRequestFlags flags) { - return mFtExtra->addExtraFile(fname, hash, size, period, flags); + return mFtExtra->addExtraFile(fname, hash, size, period, flags); } bool ftServer::ExtraFileRemove(const RsFileHash& hash, TransferRequestFlags flags) { - return mFtExtra->removeExtraFile(hash, flags); + return mFtExtra->removeExtraFile(hash, flags); } bool ftServer::ExtraFileHash(std::string localpath, uint32_t period, TransferRequestFlags flags) { - return mFtExtra->hashExtraFile(localpath, period, flags); + return mFtExtra->hashExtraFile(localpath, period, flags); } bool ftServer::ExtraFileStatus(std::string localpath, FileInfo &info) { - return mFtExtra->hashExtraFileDone(localpath, info); + return mFtExtra->hashExtraFileDone(localpath, info); } bool ftServer::ExtraFileMove(std::string fname, const RsFileHash& hash, uint64_t size, std::string destpath) { - return mFtExtra->moveExtraFile(fname, hash, size, destpath); + return mFtExtra->moveExtraFile(fname, hash, size, destpath); } /***************************************************************/ @@ -662,20 +662,20 @@ bool ftServer::ExtraFileMove(std::string fname, const RsFileHash& hash, uint64_t int ftServer::RequestDirDetails(const RsPeerId& uid, const std::string& path, DirDetails &details) { - return mFileDatabase->RequestDirDetails(uid, path, details); + return mFileDatabase->RequestDirDetails(uid, path, details); } bool ftServer::findChildPointer(void *ref, int row, void *& result, FileSearchFlags flags) { - return mFileDatabase->findChildPointer(ref,row,result,flags) ; + return mFileDatabase->findChildPointer(ref,row,result,flags) ; } int ftServer::RequestDirDetails(void *ref, DirDetails &details, FileSearchFlags flags) { - return mFileDatabase->RequestDirDetails(ref,details,flags) ; + return mFileDatabase->RequestDirDetails(ref,details,flags) ; } uint32_t ftServer::getType(void *ref, FileSearchFlags /* flags */) { - return mFileDatabase->getType(ref) ; + return mFileDatabase->getType(ref) ; } /***************************************************************/ /******************** Search Interface *************************/ @@ -683,120 +683,120 @@ uint32_t ftServer::getType(void *ref, FileSearchFlags /* flags */) int ftServer::SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags) { - return mFileDatabase->SearchKeywords(keywords, results,flags,RsPeerId()); + return mFileDatabase->SearchKeywords(keywords, results,flags,RsPeerId()); } int ftServer::SearchKeywords(std::list keywords, std::list &results,FileSearchFlags flags,const RsPeerId& peer_id) { - return mFileDatabase->SearchKeywords(keywords, results,flags,peer_id); + return mFileDatabase->SearchKeywords(keywords, results,flags,peer_id); } int ftServer::SearchBoolExp(RsRegularExpression::Expression * exp, std::list &results,FileSearchFlags flags) { - return mFileDatabase->SearchBoolExp(exp, results,flags,RsPeerId()); + return mFileDatabase->SearchBoolExp(exp, results,flags,RsPeerId()); } int ftServer::SearchBoolExp(RsRegularExpression::Expression * exp, std::list &results,FileSearchFlags flags,const RsPeerId& peer_id) { - return mFileDatabase->SearchBoolExp(exp,results,flags,peer_id) ; + return mFileDatabase->SearchBoolExp(exp,results,flags,peer_id) ; } - /***************************************************************/ - /*************** Local Shared Dir Interface ********************/ - /***************************************************************/ +/***************************************************************/ +/*************** Local Shared Dir Interface ********************/ +/***************************************************************/ bool ftServer::ConvertSharedFilePath(std::string path, std::string &fullpath) { - return mFileDatabase->convertSharedFilePath(path, fullpath); + return mFileDatabase->convertSharedFilePath(path, fullpath); } void ftServer::updateSinceGroupPermissionsChanged() { - mFileDatabase->forceSyncWithPeers(); + mFileDatabase->forceSyncWithPeers(); } void ftServer::ForceDirectoryCheck() { - mFileDatabase->forceDirectoryCheck(); - return; + mFileDatabase->forceDirectoryCheck(); + return; } bool ftServer::InDirectoryCheck() { - return mFileDatabase->inDirectoryCheck(); + return mFileDatabase->inDirectoryCheck(); } bool ftServer::getSharedDirectories(std::list &dirs) { - mFileDatabase->getSharedDirectories(dirs); - return true; + mFileDatabase->getSharedDirectories(dirs); + return true; } bool ftServer::setSharedDirectories(const std::list& dirs) { - mFileDatabase->setSharedDirectories(dirs); - return true; + mFileDatabase->setSharedDirectories(dirs); + return true; } bool ftServer::addSharedDirectory(const SharedDirInfo& dir) { - SharedDirInfo _dir = dir; - _dir.filename = RsDirUtil::convertPathToUnix(_dir.filename); + SharedDirInfo _dir = dir; + _dir.filename = RsDirUtil::convertPathToUnix(_dir.filename); - std::list dirList; - mFileDatabase->getSharedDirectories(dirList); + std::list dirList; + mFileDatabase->getSharedDirectories(dirList); - // check that the directory is not already in the list. - for(std::list::const_iterator it(dirList.begin());it!=dirList.end();++it) - if((*it).filename == _dir.filename) - return false ; + // check that the directory is not already in the list. + for(std::list::const_iterator it(dirList.begin());it!=dirList.end();++it) + if((*it).filename == _dir.filename) + return false ; - // ok then, add the shared directory. - dirList.push_back(_dir); + // ok then, add the shared directory. + dirList.push_back(_dir); - mFileDatabase->setSharedDirectories(dirList); - return true; + mFileDatabase->setSharedDirectories(dirList); + return true; } bool ftServer::updateShareFlags(const SharedDirInfo& info) { - mFileDatabase->updateShareFlags(info); + mFileDatabase->updateShareFlags(info); - return true ; + return true ; } bool ftServer::removeSharedDirectory(std::string dir) { - dir = RsDirUtil::convertPathToUnix(dir); + dir = RsDirUtil::convertPathToUnix(dir); - std::list dirList; - std::list::iterator it; + std::list dirList; + std::list::iterator it; #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "ftServer::removeSharedDirectory(" << dir << ")" << std::endl; + FTSERVER_DEBUG() << "ftServer::removeSharedDirectory(" << dir << ")" << std::endl; #endif - mFileDatabase->getSharedDirectories(dirList); + mFileDatabase->getSharedDirectories(dirList); #ifdef SERVER_DEBUG - for(it = dirList.begin(); it != dirList.end(); ++it) - FTSERVER_DEBUG() << " existing: " << (*it).filename << std::endl; + for(it = dirList.begin(); it != dirList.end(); ++it) + FTSERVER_DEBUG() << " existing: " << (*it).filename << std::endl; #endif - for(it = dirList.begin();it!=dirList.end() && (*it).filename != dir;++it) ; + for(it = dirList.begin();it!=dirList.end() && (*it).filename != dir;++it) ; - if(it == dirList.end()) - { - FTSERVER_ERROR() << "(EE) ftServer::removeSharedDirectory(): Cannot Find Directory... Fail" << std::endl; - return false; - } + if(it == dirList.end()) + { + FTSERVER_ERROR() << "(EE) ftServer::removeSharedDirectory(): Cannot Find Directory... Fail" << std::endl; + return false; + } #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << " Updating Directories" << std::endl; + FTSERVER_DEBUG() << " Updating Directories" << std::endl; #endif - dirList.erase(it); - mFileDatabase->setSharedDirectories(dirList); + dirList.erase(it); + mFileDatabase->setSharedDirectories(dirList); - return true; + return true; } bool ftServer::watchEnabled() { return mFileDatabase->watchEnabled() ; } int ftServer::watchPeriod() const { return mFileDatabase->watchPeriod()/60 ; } @@ -806,330 +806,330 @@ void ftServer::setWatchPeriod(int minutes) { mFileDatabase->set bool ftServer::getShareDownloadDirectory() { - std::list dirList; - mFileDatabase->getSharedDirectories(dirList); + std::list dirList; + mFileDatabase->getSharedDirectories(dirList); - std::string dir = mFtController->getDownloadDirectory(); + std::string dir = mFtController->getDownloadDirectory(); - // check if the download directory is in the list. - for (std::list::const_iterator it(dirList.begin()); it != dirList.end(); ++it) - if ((*it).filename == dir) - return true; + // check if the download directory is in the list. + for (std::list::const_iterator it(dirList.begin()); it != dirList.end(); ++it) + if ((*it).filename == dir) + return true; - return false; + return false; } bool ftServer::shareDownloadDirectory(bool share) { - if (share) - { - /* Share */ - SharedDirInfo inf ; - inf.filename = mFtController->getDownloadDirectory(); - inf.shareflags = DIR_FLAGS_ANONYMOUS_DOWNLOAD ; + if (share) + { + /* Share */ + SharedDirInfo inf ; + inf.filename = mFtController->getDownloadDirectory(); + inf.shareflags = DIR_FLAGS_ANONYMOUS_DOWNLOAD ; - return addSharedDirectory(inf); - } - else - { - /* Unshare */ - std::string dir = mFtController->getDownloadDirectory(); - return removeSharedDirectory(dir); - } + return addSharedDirectory(inf); + } + else + { + /* Unshare */ + std::string dir = mFtController->getDownloadDirectory(); + return removeSharedDirectory(dir); + } } - /***************************************************************/ - /****************** End of RsFiles Interface *******************/ - /***************************************************************/ +/***************************************************************/ +/****************** End of RsFiles Interface *******************/ +/***************************************************************/ //bool ftServer::loadConfigMap(std::map &/*configMap*/) //{ // return true; //} - /***************************************************************/ - /********************** Data Flow **********************/ - /***************************************************************/ +/***************************************************************/ +/********************** Data Flow **********************/ +/***************************************************************/ bool ftServer::sendTurtleItem(const RsPeerId& peerId,const RsFileHash& hash,RsTurtleGenericTunnelItem *item) { - // we cannot look in the encrypted hash map, since the same hash--on this side of the FT--can be used with both - // encrypted and unencrypted peers ids. So the information comes from the virtual peer Id. + // we cannot look in the encrypted hash map, since the same hash--on this side of the FT--can be used with both + // encrypted and unencrypted peers ids. So the information comes from the virtual peer Id. - RsFileHash encrypted_hash; + RsFileHash encrypted_hash; - if(findEncryptedHash(peerId,encrypted_hash)) - { - // we encrypt the item + if(findEncryptedHash(peerId,encrypted_hash)) + { + // we encrypt the item #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "Sending turtle item to peer ID " << peerId << " using encrypted tunnel." << std::endl; + FTSERVER_DEBUG() << "Sending turtle item to peer ID " << peerId << " using encrypted tunnel." << std::endl; #endif - RsTurtleGenericDataItem *encrypted_item ; + RsTurtleGenericDataItem *encrypted_item ; - if(!encryptItem(item, hash, encrypted_item)) - return false ; + if(!encryptItem(item, hash, encrypted_item)) + return false ; - delete item ; + delete item ; - mTurtleRouter->sendTurtleData(peerId,encrypted_item) ; - } - else - { + mTurtleRouter->sendTurtleData(peerId,encrypted_item) ; + } + else + { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "Sending turtle item to peer ID " << peerId << " using non uncrypted tunnel." << std::endl; + FTSERVER_DEBUG() << "Sending turtle item to peer ID " << peerId << " using non uncrypted tunnel." << std::endl; #endif - mTurtleRouter->sendTurtleData(peerId,item) ; - } + mTurtleRouter->sendTurtleData(peerId,item) ; + } - return true ; + return true ; } - /* Client Send */ +/* Client Send */ bool ftServer::sendDataRequest(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t offset, uint32_t chunksize) { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "ftServer::sendDataRequest() to peer " << peerId << " for hash " << hash << ", offset=" << offset << ", chunk size="<< chunksize << std::endl; + FTSERVER_DEBUG() << "ftServer::sendDataRequest() to peer " << peerId << " for hash " << hash << ", offset=" << offset << ", chunk size="<< chunksize << std::endl; #endif - if(mTurtleRouter->isTurtlePeer(peerId)) - { - RsTurtleFileRequestItem *item = new RsTurtleFileRequestItem ; + if(mTurtleRouter->isTurtlePeer(peerId)) + { + RsTurtleFileRequestItem *item = new RsTurtleFileRequestItem ; - item->chunk_offset = offset ; - item->chunk_size = chunksize ; + item->chunk_offset = offset ; + item->chunk_size = chunksize ; - sendTurtleItem(peerId,hash,item) ; - } - else - { - /* create a packet */ - /* push to networking part */ - RsFileTransferDataRequestItem *rfi = new RsFileTransferDataRequestItem(); + sendTurtleItem(peerId,hash,item) ; + } + else + { + /* create a packet */ + /* push to networking part */ + RsFileTransferDataRequestItem *rfi = new RsFileTransferDataRequestItem(); - /* id */ - rfi->PeerId(peerId); + /* id */ + rfi->PeerId(peerId); - /* file info */ - rfi->file.filesize = size; - rfi->file.hash = hash; /* ftr->hash; */ + /* file info */ + rfi->file.filesize = size; + rfi->file.hash = hash; /* ftr->hash; */ - /* offsets */ - rfi->fileoffset = offset; /* ftr->offset; */ - rfi->chunksize = chunksize; /* ftr->chunk; */ + /* offsets */ + rfi->fileoffset = offset; /* ftr->offset; */ + rfi->chunksize = chunksize; /* ftr->chunk; */ - sendItem(rfi); - } + sendItem(rfi); + } - return true; + return true; } bool ftServer::sendChunkMapRequest(const RsPeerId& peerId,const RsFileHash& hash,bool is_client) { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "ftServer::sendChunkMapRequest() to peer " << peerId << " for hash " << hash << std::endl; + FTSERVER_DEBUG() << "ftServer::sendChunkMapRequest() to peer " << peerId << " for hash " << hash << std::endl; #endif - if(mTurtleRouter->isTurtlePeer(peerId)) - { - RsTurtleFileMapRequestItem *item = new RsTurtleFileMapRequestItem ; - sendTurtleItem(peerId,hash,item) ; - } - else - { - /* create a packet */ - /* push to networking part */ - RsFileTransferChunkMapRequestItem *rfi = new RsFileTransferChunkMapRequestItem(); + if(mTurtleRouter->isTurtlePeer(peerId)) + { + RsTurtleFileMapRequestItem *item = new RsTurtleFileMapRequestItem ; + sendTurtleItem(peerId,hash,item) ; + } + else + { + /* create a packet */ + /* push to networking part */ + RsFileTransferChunkMapRequestItem *rfi = new RsFileTransferChunkMapRequestItem(); - /* id */ - rfi->PeerId(peerId); + /* id */ + rfi->PeerId(peerId); - /* file info */ - rfi->hash = hash; /* ftr->hash; */ - rfi->is_client = is_client ; + /* file info */ + rfi->hash = hash; /* ftr->hash; */ + rfi->is_client = is_client ; - sendItem(rfi); - } + sendItem(rfi); + } - return true ; + return true ; } bool ftServer::sendChunkMap(const RsPeerId& peerId,const RsFileHash& hash,const CompressedChunkMap& map,bool is_client) { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "ftServer::sendChunkMap() to peer " << peerId << " for hash " << hash << std::endl; + FTSERVER_DEBUG() << "ftServer::sendChunkMap() to peer " << peerId << " for hash " << hash << std::endl; #endif - if(mTurtleRouter->isTurtlePeer(peerId)) - { - RsTurtleFileMapItem *item = new RsTurtleFileMapItem ; - item->compressed_map = map ; - sendTurtleItem(peerId,hash,item) ; - } - else - { - /* create a packet */ - /* push to networking part */ - RsFileTransferChunkMapItem *rfi = new RsFileTransferChunkMapItem(); + if(mTurtleRouter->isTurtlePeer(peerId)) + { + RsTurtleFileMapItem *item = new RsTurtleFileMapItem ; + item->compressed_map = map ; + sendTurtleItem(peerId,hash,item) ; + } + else + { + /* create a packet */ + /* push to networking part */ + RsFileTransferChunkMapItem *rfi = new RsFileTransferChunkMapItem(); - /* id */ - rfi->PeerId(peerId); + /* id */ + rfi->PeerId(peerId); - /* file info */ - rfi->hash = hash; /* ftr->hash; */ - rfi->is_client = is_client; /* ftr->hash; */ - rfi->compressed_map = map; /* ftr->hash; */ + /* file info */ + rfi->hash = hash; /* ftr->hash; */ + rfi->is_client = is_client; /* ftr->hash; */ + rfi->compressed_map = map; /* ftr->hash; */ - sendItem(rfi); - } + sendItem(rfi); + } - return true ; + return true ; } bool ftServer::sendSingleChunkCRCRequest(const RsPeerId& peerId,const RsFileHash& hash,uint32_t chunk_number) { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "ftServer::sendSingleCRCRequest() to peer " << peerId << " for hash " << hash << ", chunk number=" << chunk_number << std::endl; + FTSERVER_DEBUG() << "ftServer::sendSingleCRCRequest() to peer " << peerId << " for hash " << hash << ", chunk number=" << chunk_number << std::endl; #endif - if(mTurtleRouter->isTurtlePeer(peerId)) - { - RsTurtleChunkCrcRequestItem *item = new RsTurtleChunkCrcRequestItem; - item->chunk_number = chunk_number ; + if(mTurtleRouter->isTurtlePeer(peerId)) + { + RsTurtleChunkCrcRequestItem *item = new RsTurtleChunkCrcRequestItem; + item->chunk_number = chunk_number ; - sendTurtleItem(peerId,hash,item) ; - } - else - { - /* create a packet */ - /* push to networking part */ - RsFileTransferSingleChunkCrcRequestItem *rfi = new RsFileTransferSingleChunkCrcRequestItem(); + sendTurtleItem(peerId,hash,item) ; + } + else + { + /* create a packet */ + /* push to networking part */ + RsFileTransferSingleChunkCrcRequestItem *rfi = new RsFileTransferSingleChunkCrcRequestItem(); - /* id */ - rfi->PeerId(peerId); + /* id */ + rfi->PeerId(peerId); - /* file info */ - rfi->hash = hash; /* ftr->hash; */ - rfi->chunk_number = chunk_number ; + /* file info */ + rfi->hash = hash; /* ftr->hash; */ + rfi->chunk_number = chunk_number ; - sendItem(rfi); - } + sendItem(rfi); + } - return true ; + return true ; } bool ftServer::sendSingleChunkCRC(const RsPeerId& peerId,const RsFileHash& hash,uint32_t chunk_number,const Sha1CheckSum& crc) { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "ftServer::sendSingleCRC() to peer " << peerId << " for hash " << hash << ", chunk number=" << chunk_number << std::endl; + FTSERVER_DEBUG() << "ftServer::sendSingleCRC() to peer " << peerId << " for hash " << hash << ", chunk number=" << chunk_number << std::endl; #endif - if(mTurtleRouter->isTurtlePeer(peerId)) - { - RsTurtleChunkCrcItem *item = new RsTurtleChunkCrcItem; - item->chunk_number = chunk_number ; - item->check_sum = crc ; + if(mTurtleRouter->isTurtlePeer(peerId)) + { + RsTurtleChunkCrcItem *item = new RsTurtleChunkCrcItem; + item->chunk_number = chunk_number ; + item->check_sum = crc ; - sendTurtleItem(peerId,hash,item) ; - } - else - { - /* create a packet */ - /* push to networking part */ - RsFileTransferSingleChunkCrcItem *rfi = new RsFileTransferSingleChunkCrcItem(); + sendTurtleItem(peerId,hash,item) ; + } + else + { + /* create a packet */ + /* push to networking part */ + RsFileTransferSingleChunkCrcItem *rfi = new RsFileTransferSingleChunkCrcItem(); - /* id */ - rfi->PeerId(peerId); + /* id */ + rfi->PeerId(peerId); - /* file info */ - rfi->hash = hash; /* ftr->hash; */ - rfi->check_sum = crc; - rfi->chunk_number = chunk_number; + /* file info */ + rfi->hash = hash; /* ftr->hash; */ + rfi->check_sum = crc; + rfi->chunk_number = chunk_number; - sendItem(rfi); - } + sendItem(rfi); + } - return true ; + return true ; } - /* Server Send */ +/* Server Send */ bool ftServer::sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t size, uint64_t baseoffset, uint32_t chunksize, void *data) { - /* create a packet */ - /* push to networking part */ - uint32_t tosend = chunksize; - uint64_t offset = 0; - uint32_t chunk; + /* create a packet */ + /* push to networking part */ + uint32_t tosend = chunksize; + uint64_t offset = 0; + uint32_t chunk; #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "ftServer::sendData() to " << peerId << ", hash: " << hash << " offset: " << baseoffset << " chunk: " << chunksize << " data: " << data << std::endl; + FTSERVER_DEBUG() << "ftServer::sendData() to " << peerId << ", hash: " << hash << " offset: " << baseoffset << " chunk: " << chunksize << " data: " << data << std::endl; #endif - while(tosend > 0) - { - //static const uint32_t MAX_FT_CHUNK = 32 * 1024; /* 32K */ - //static const uint32_t MAX_FT_CHUNK = 16 * 1024; /* 16K */ - // - static const uint32_t MAX_FT_CHUNK = 8 * 1024; /* 16K */ + while(tosend > 0) + { + //static const uint32_t MAX_FT_CHUNK = 32 * 1024; /* 32K */ + //static const uint32_t MAX_FT_CHUNK = 16 * 1024; /* 16K */ + // + static const uint32_t MAX_FT_CHUNK = 8 * 1024; /* 16K */ - /* workout size */ - chunk = MAX_FT_CHUNK; - if (chunk > tosend) - { - chunk = tosend; - } + /* workout size */ + chunk = MAX_FT_CHUNK; + if (chunk > tosend) + { + chunk = tosend; + } - /******** New Serialiser Type *******/ + /******** New Serialiser Type *******/ - if(mTurtleRouter->isTurtlePeer(peerId)) - { - RsTurtleFileDataItem *item = new RsTurtleFileDataItem ; + if(mTurtleRouter->isTurtlePeer(peerId)) + { + RsTurtleFileDataItem *item = new RsTurtleFileDataItem ; - item->chunk_offset = offset+baseoffset ; - item->chunk_size = chunk; - item->chunk_data = rs_malloc(chunk) ; + item->chunk_offset = offset+baseoffset ; + item->chunk_size = chunk; + item->chunk_data = rs_malloc(chunk) ; - if(item->chunk_data == NULL) - { - delete item; - return false; - } - memcpy(item->chunk_data,&(((uint8_t *) data)[offset]),chunk) ; + if(item->chunk_data == NULL) + { + delete item; + return false; + } + memcpy(item->chunk_data,&(((uint8_t *) data)[offset]),chunk) ; - sendTurtleItem(peerId,hash,item) ; - } - else - { - RsFileTransferDataItem *rfd = new RsFileTransferDataItem(); + sendTurtleItem(peerId,hash,item) ; + } + else + { + RsFileTransferDataItem *rfd = new RsFileTransferDataItem(); - /* set id */ - rfd->PeerId(peerId); + /* set id */ + rfd->PeerId(peerId); - /* file info */ - rfd->fd.file.filesize = size; - rfd->fd.file.hash = hash; - rfd->fd.file.name = ""; /* blank other data */ - rfd->fd.file.path = ""; - rfd->fd.file.pop = 0; - rfd->fd.file.age = 0; + /* file info */ + rfd->fd.file.filesize = size; + rfd->fd.file.hash = hash; + rfd->fd.file.name = ""; /* blank other data */ + rfd->fd.file.path = ""; + rfd->fd.file.pop = 0; + rfd->fd.file.age = 0; - rfd->fd.file_offset = baseoffset + offset; + rfd->fd.file_offset = baseoffset + offset; - /* file data */ - rfd->fd.binData.setBinData( &(((uint8_t *) data)[offset]), chunk); + /* file data */ + rfd->fd.binData.setBinData( &(((uint8_t *) data)[offset]), chunk); - sendItem(rfd); + sendItem(rfd); - /* print the data pointer */ + /* print the data pointer */ #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "ftServer::sendData() Packet: " << " offset: " << rfd->fd.file_offset << " chunk: " << chunk << " len: " << rfd->fd.binData.bin_len << " data: " << rfd->fd.binData.bin_data << std::endl; + FTSERVER_DEBUG() << "ftServer::sendData() Packet: " << " offset: " << rfd->fd.file_offset << " chunk: " << chunk << " len: " << rfd->fd.binData.bin_len << " data: " << rfd->fd.binData.bin_data << std::endl; #endif - } + } - offset += chunk; - tosend -= chunk; - } + offset += chunk; + tosend -= chunk; + } - /* clean up data */ - free(data); + /* clean up data */ + free(data); - return true; + return true; } // Encrypts the given item using aead-chacha20-poly1305 @@ -1150,15 +1150,15 @@ bool ftServer::sendData(const RsPeerId& peerId, const RsFileHash& hash, uint64_t void ftServer::deriveEncryptionKey(const RsFileHash& hash, uint8_t *key) { - // The encryption key is simply the 256 hash of the - SHA256_CTX sha_ctx ; + // The encryption key is simply the 256 hash of the + SHA256_CTX sha_ctx ; - if(SHA256_DIGEST_LENGTH != 32) - throw std::runtime_error("Warning: can't compute Sha1Sum with sum size != 32") ; + if(SHA256_DIGEST_LENGTH != 32) + throw std::runtime_error("Warning: can't compute Sha1Sum with sum size != 32") ; - SHA256_Init(&sha_ctx); - SHA256_Update(&sha_ctx, hash.toByteArray(), hash.SIZE_IN_BYTES); - SHA256_Final (key, &sha_ctx); + SHA256_Init(&sha_ctx); + SHA256_Update(&sha_ctx, hash.toByteArray(), hash.SIZE_IN_BYTES); + SHA256_Final (key, &sha_ctx); } static const uint32_t ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE = 12 ; @@ -1172,316 +1172,316 @@ static const uint8_t ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_SHA256 = 0x02 ; bool ftServer::encryptItem(RsTurtleGenericTunnelItem *clear_item,const RsFileHash& hash,RsTurtleGenericDataItem *& encrypted_item) { - uint8_t initialization_vector[ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE] ; + uint8_t initialization_vector[ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE] ; - RSRandom::random_bytes(initialization_vector,ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE) ; + RSRandom::random_bytes(initialization_vector,ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE) ; #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "ftServer::Encrypting ft item." << std::endl; - FTSERVER_DEBUG() << " random nonce : " << RsUtil::BinToHex(initialization_vector,ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE) << std::endl; + FTSERVER_DEBUG() << "ftServer::Encrypting ft item." << std::endl; + FTSERVER_DEBUG() << " random nonce : " << RsUtil::BinToHex(initialization_vector,ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE) << std::endl; #endif - uint32_t total_data_size = ENCRYPTED_FT_HEADER_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_EDATA_SIZE + clear_item->serial_size() + ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE ; + uint32_t total_data_size = ENCRYPTED_FT_HEADER_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_EDATA_SIZE + clear_item->serial_size() + ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE ; #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << " clear part size : " << clear_item->serial_size() << std::endl; - FTSERVER_DEBUG() << " total item size : " << total_data_size << std::endl; + FTSERVER_DEBUG() << " clear part size : " << clear_item->serial_size() << std::endl; + FTSERVER_DEBUG() << " total item size : " << total_data_size << std::endl; #endif - encrypted_item = new RsTurtleGenericDataItem ; - encrypted_item->data_bytes = rs_malloc( total_data_size ) ; - encrypted_item->data_size = total_data_size ; + encrypted_item = new RsTurtleGenericDataItem ; + encrypted_item->data_bytes = rs_malloc( total_data_size ) ; + encrypted_item->data_size = total_data_size ; - if(encrypted_item->data_bytes == NULL) - return false ; + if(encrypted_item->data_bytes == NULL) + return false ; - uint8_t *edata = (uint8_t*)encrypted_item->data_bytes ; - uint32_t edata_size = clear_item->serial_size() ; - uint32_t offset = 0; + uint8_t *edata = (uint8_t*)encrypted_item->data_bytes ; + uint32_t edata_size = clear_item->serial_size() ; + uint32_t offset = 0; - edata[0] = 0xae ; - edata[1] = 0xad ; - edata[2] = ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_SHA256 ; // means AEAD_chacha20_sha256 - edata[3] = 0x01 ; + edata[0] = 0xae ; + edata[1] = 0xad ; + edata[2] = ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_SHA256 ; // means AEAD_chacha20_sha256 + edata[3] = 0x01 ; - offset += ENCRYPTED_FT_HEADER_SIZE; - uint32_t aad_offset = offset ; - uint32_t aad_size = ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_EDATA_SIZE ; + offset += ENCRYPTED_FT_HEADER_SIZE; + uint32_t aad_offset = offset ; + uint32_t aad_size = ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_EDATA_SIZE ; - memcpy(&edata[offset], initialization_vector, ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE) ; - offset += ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE ; + memcpy(&edata[offset], initialization_vector, ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE) ; + offset += ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE ; - edata[offset+0] = (edata_size >> 0) & 0xff ; - edata[offset+1] = (edata_size >> 8) & 0xff ; - edata[offset+2] = (edata_size >> 16) & 0xff ; - edata[offset+3] = (edata_size >> 24) & 0xff ; + edata[offset+0] = (edata_size >> 0) & 0xff ; + edata[offset+1] = (edata_size >> 8) & 0xff ; + edata[offset+2] = (edata_size >> 16) & 0xff ; + edata[offset+3] = (edata_size >> 24) & 0xff ; - offset += ENCRYPTED_FT_EDATA_SIZE ; + offset += ENCRYPTED_FT_EDATA_SIZE ; - uint32_t ser_size = (uint32_t)((int)total_data_size - (int)offset); - clear_item->serialize(&edata[offset], ser_size); + uint32_t ser_size = (uint32_t)((int)total_data_size - (int)offset); + clear_item->serialize(&edata[offset], ser_size); #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << " clear item : " << RsUtil::BinToHex(&edata[offset],std::min(50,(int)total_data_size-(int)offset)) << "(...)" << std::endl; + FTSERVER_DEBUG() << " clear item : " << RsUtil::BinToHex(&edata[offset],std::min(50,(int)total_data_size-(int)offset)) << "(...)" << std::endl; #endif - uint32_t clear_item_offset = offset ; - offset += edata_size ; + uint32_t clear_item_offset = offset ; + offset += edata_size ; - uint32_t authentication_tag_offset = offset ; - assert(ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE + offset == total_data_size) ; + uint32_t authentication_tag_offset = offset ; + assert(ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE + offset == total_data_size) ; - uint8_t encryption_key[32] ; - deriveEncryptionKey(hash,encryption_key) ; + uint8_t encryption_key[32] ; + deriveEncryptionKey(hash,encryption_key) ; - if(edata[2] == ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_POLY1305) - librs::crypto::AEAD_chacha20_poly1305(encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset],true) ; - else if(edata[2] == ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_SHA256) - librs::crypto::AEAD_chacha20_sha256 (encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset],true) ; - else - return false ; + if(edata[2] == ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_POLY1305) + librs::crypto::AEAD_chacha20_poly1305(encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset],true) ; + else if(edata[2] == ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_SHA256) + librs::crypto::AEAD_chacha20_sha256 (encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset],true) ; + else + return false ; #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << " encryption key : " << RsUtil::BinToHex(encryption_key,32) << std::endl; - FTSERVER_DEBUG() << " authen. tag : " << RsUtil::BinToHex(&edata[authentication_tag_offset],ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE) << std::endl; - FTSERVER_DEBUG() << " final item : " << RsUtil::BinToHex(&edata[0],std::min(50u,total_data_size)) << "(...)" << std::endl; + FTSERVER_DEBUG() << " encryption key : " << RsUtil::BinToHex(encryption_key,32) << std::endl; + FTSERVER_DEBUG() << " authen. tag : " << RsUtil::BinToHex(&edata[authentication_tag_offset],ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE) << std::endl; + FTSERVER_DEBUG() << " final item : " << RsUtil::BinToHex(&edata[0],std::min(50u,total_data_size)) << "(...)" << std::endl; #endif - return true ; + return true ; } // Decrypts the given item using aead-chacha20-poly1305 bool ftServer::decryptItem(RsTurtleGenericDataItem *encrypted_item,const RsFileHash& hash,RsTurtleGenericTunnelItem *& decrypted_item) { - uint8_t encryption_key[32] ; - deriveEncryptionKey(hash,encryption_key) ; + uint8_t encryption_key[32] ; + deriveEncryptionKey(hash,encryption_key) ; - uint8_t *edata = (uint8_t*)encrypted_item->data_bytes ; - uint32_t offset = 0; + uint8_t *edata = (uint8_t*)encrypted_item->data_bytes ; + uint32_t offset = 0; - if(encrypted_item->data_size < ENCRYPTED_FT_HEADER_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_EDATA_SIZE) return false ; + if(encrypted_item->data_size < ENCRYPTED_FT_HEADER_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_EDATA_SIZE) return false ; - if(edata[0] != 0xae) return false ; - if(edata[1] != 0xad) return false ; - if(edata[2] != ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_POLY1305 && edata[2] != ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_SHA256) return false ; - if(edata[3] != 0x01) return false ; + if(edata[0] != 0xae) return false ; + if(edata[1] != 0xad) return false ; + if(edata[2] != ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_POLY1305 && edata[2] != ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_SHA256) return false ; + if(edata[3] != 0x01) return false ; - offset += ENCRYPTED_FT_HEADER_SIZE ; - uint32_t aad_offset = offset ; - uint32_t aad_size = ENCRYPTED_FT_EDATA_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE ; + offset += ENCRYPTED_FT_HEADER_SIZE ; + uint32_t aad_offset = offset ; + uint32_t aad_size = ENCRYPTED_FT_EDATA_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE ; - uint8_t *initialization_vector = &edata[offset] ; + uint8_t *initialization_vector = &edata[offset] ; #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "ftServer::decrypting ft item." << std::endl; - FTSERVER_DEBUG() << " item data : " << RsUtil::BinToHex(edata,std::min(50u,encrypted_item->data_size)) << "(...)" << std::endl; - FTSERVER_DEBUG() << " hash : " << hash << std::endl; - FTSERVER_DEBUG() << " encryption key : " << RsUtil::BinToHex(encryption_key,32) << std::endl; - FTSERVER_DEBUG() << " random nonce : " << RsUtil::BinToHex(initialization_vector,ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE) << std::endl; + FTSERVER_DEBUG() << "ftServer::decrypting ft item." << std::endl; + FTSERVER_DEBUG() << " item data : " << RsUtil::BinToHex(edata,std::min(50u,encrypted_item->data_size)) << "(...)" << std::endl; + FTSERVER_DEBUG() << " hash : " << hash << std::endl; + FTSERVER_DEBUG() << " encryption key : " << RsUtil::BinToHex(encryption_key,32) << std::endl; + FTSERVER_DEBUG() << " random nonce : " << RsUtil::BinToHex(initialization_vector,ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE) << std::endl; #endif - offset += ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE ; + offset += ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE ; - uint32_t edata_size = 0 ; - edata_size += ((uint32_t)edata[offset+0]) << 0 ; - edata_size += ((uint32_t)edata[offset+1]) << 8 ; - edata_size += ((uint32_t)edata[offset+2]) << 16 ; - edata_size += ((uint32_t)edata[offset+3]) << 24 ; + uint32_t edata_size = 0 ; + edata_size += ((uint32_t)edata[offset+0]) << 0 ; + edata_size += ((uint32_t)edata[offset+1]) << 8 ; + edata_size += ((uint32_t)edata[offset+2]) << 16 ; + edata_size += ((uint32_t)edata[offset+3]) << 24 ; - if(edata_size + ENCRYPTED_FT_EDATA_SIZE + ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_HEADER_SIZE != encrypted_item->data_size) - { - FTSERVER_ERROR() << " ERROR: encrypted data size is " << edata_size << ", should be " << encrypted_item->data_size - (ENCRYPTED_FT_EDATA_SIZE + ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_HEADER_SIZE ) << std::endl; - return false ; - } + if(edata_size + ENCRYPTED_FT_EDATA_SIZE + ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_HEADER_SIZE != encrypted_item->data_size) + { + FTSERVER_ERROR() << " ERROR: encrypted data size is " << edata_size << ", should be " << encrypted_item->data_size - (ENCRYPTED_FT_EDATA_SIZE + ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE + ENCRYPTED_FT_INITIALIZATION_VECTOR_SIZE + ENCRYPTED_FT_HEADER_SIZE ) << std::endl; + return false ; + } - offset += ENCRYPTED_FT_EDATA_SIZE ; - uint32_t clear_item_offset = offset ; + offset += ENCRYPTED_FT_EDATA_SIZE ; + uint32_t clear_item_offset = offset ; - uint32_t authentication_tag_offset = offset + edata_size ; + uint32_t authentication_tag_offset = offset + edata_size ; #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << " authen. tag : " << RsUtil::BinToHex(&edata[authentication_tag_offset],ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE) << std::endl; + FTSERVER_DEBUG() << " authen. tag : " << RsUtil::BinToHex(&edata[authentication_tag_offset],ENCRYPTED_FT_AUTHENTICATION_TAG_SIZE) << std::endl; #endif - bool result ; + bool result ; - if(edata[2] == ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_POLY1305) - result = librs::crypto::AEAD_chacha20_poly1305(encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset],false) ; - else if(edata[2] == ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_SHA256) - result = librs::crypto::AEAD_chacha20_sha256 (encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset],false) ; - else - return false ; + if(edata[2] == ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_POLY1305) + result = librs::crypto::AEAD_chacha20_poly1305(encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset],false) ; + else if(edata[2] == ENCRYPTED_FT_FORMAT_AEAD_CHACHA20_SHA256) + result = librs::crypto::AEAD_chacha20_sha256 (encryption_key,initialization_vector,&edata[clear_item_offset],edata_size, &edata[aad_offset],aad_size, &edata[authentication_tag_offset],false) ; + else + return false ; #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << " authen. result : " << result << std::endl; - FTSERVER_DEBUG() << " decrypted daya : " << RsUtil::BinToHex(&edata[clear_item_offset],std::min(50u,edata_size)) << "(...)" << std::endl; + FTSERVER_DEBUG() << " authen. result : " << result << std::endl; + FTSERVER_DEBUG() << " decrypted daya : " << RsUtil::BinToHex(&edata[clear_item_offset],std::min(50u,edata_size)) << "(...)" << std::endl; #endif - if(!result) - { - FTSERVER_ERROR() << "(EE) decryption/authentication went wrong." << std::endl; - return false ; - } + if(!result) + { + FTSERVER_ERROR() << "(EE) decryption/authentication went wrong." << std::endl; + return false ; + } - decrypted_item = deserialiseItem(&edata[clear_item_offset],edata_size) ; + decrypted_item = deserialiseItem(&edata[clear_item_offset],edata_size) ; - if(decrypted_item == NULL) - return false ; + if(decrypted_item == NULL) + return false ; - return true ; + return true ; } bool ftServer::encryptHash(const RsFileHash& hash, RsFileHash& hash_of_hash) { - hash_of_hash = RsDirUtil::sha1sum(hash.toByteArray(),hash.SIZE_IN_BYTES); - return true ; + hash_of_hash = RsDirUtil::sha1sum(hash.toByteArray(),hash.SIZE_IN_BYTES); + return true ; } bool ftServer::findEncryptedHash(const RsPeerId& virtual_peer_id, RsFileHash& encrypted_hash) { - RS_STACK_MUTEX(srvMutex); + RS_STACK_MUTEX(srvMutex); - std::map::const_iterator it = mEncryptedPeerIds.find(virtual_peer_id) ; + std::map::const_iterator it = mEncryptedPeerIds.find(virtual_peer_id) ; - if(it != mEncryptedPeerIds.end()) - { - encrypted_hash = it->second ; - return true ; - } - else - return false ; + if(it != mEncryptedPeerIds.end()) + { + encrypted_hash = it->second ; + return true ; + } + else + return false ; } bool ftServer::findRealHash(const RsFileHash& hash, RsFileHash& real_hash) { - RS_STACK_MUTEX(srvMutex); - std::map::const_iterator it = mEncryptedHashes.find(hash) ; + RS_STACK_MUTEX(srvMutex); + std::map::const_iterator it = mEncryptedHashes.find(hash) ; - if(it != mEncryptedHashes.end()) - { - real_hash = it->second ; - return true ; - } - else - return false ; + if(it != mEncryptedHashes.end()) + { + real_hash = it->second ; + return true ; + } + else + return false ; } // Dont delete the item. The client (p3turtle) is doing it after calling this. // void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i, - const RsFileHash& hash, - const RsPeerId& virtual_peer_id, - RsTurtleGenericTunnelItem::Direction direction) + const RsFileHash& hash, + const RsPeerId& virtual_peer_id, + RsTurtleGenericTunnelItem::Direction direction) { - if(i->PacketSubType() == RS_TURTLE_SUBTYPE_GENERIC_DATA) - { + if(i->PacketSubType() == RS_TURTLE_SUBTYPE_GENERIC_DATA) + { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "Received encrypted data item. Trying to decrypt" << std::endl; + FTSERVER_DEBUG() << "Received encrypted data item. Trying to decrypt" << std::endl; #endif - RsFileHash real_hash ; + RsFileHash real_hash ; - if(!findRealHash(hash,real_hash)) - { - FTSERVER_ERROR() << "(EE) Cannot find real hash for encrypted data item with H(H(F))=" << hash << ". This is unexpected." << std::endl; - return ; - } + if(!findRealHash(hash,real_hash)) + { + FTSERVER_ERROR() << "(EE) Cannot find real hash for encrypted data item with H(H(F))=" << hash << ". This is unexpected." << std::endl; + return ; + } - RsTurtleGenericTunnelItem *decrypted_item ; - if(!decryptItem(dynamic_cast(i),real_hash,decrypted_item)) - { - FTSERVER_ERROR() << "(EE) decryption error." << std::endl; - return ; - } + RsTurtleGenericTunnelItem *decrypted_item ; + if(!decryptItem(dynamic_cast(i),real_hash,decrypted_item)) + { + FTSERVER_ERROR() << "(EE) decryption error." << std::endl; + return ; + } - receiveTurtleData(decrypted_item, real_hash, virtual_peer_id,direction) ; + receiveTurtleData(decrypted_item, real_hash, virtual_peer_id,direction) ; - delete decrypted_item ; - return ; - } + delete decrypted_item ; + return ; + } - switch(i->PacketSubType()) - { - case RS_TURTLE_SUBTYPE_FILE_REQUEST: - { - RsTurtleFileRequestItem *item = dynamic_cast(i) ; - if (item) - { + switch(i->PacketSubType()) + { + case RS_TURTLE_SUBTYPE_FILE_REQUEST: + { + RsTurtleFileRequestItem *item = dynamic_cast(i) ; + if (item) + { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received file data request for " << hash << " from peer " << virtual_peer_id << std::endl; + FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received file data request for " << hash << " from peer " << virtual_peer_id << std::endl; #endif - getMultiplexer()->recvDataRequest(virtual_peer_id,hash,0,item->chunk_offset,item->chunk_size) ; - } - } - break ; + getMultiplexer()->recvDataRequest(virtual_peer_id,hash,0,item->chunk_offset,item->chunk_size) ; + } + } + break ; - case RS_TURTLE_SUBTYPE_FILE_DATA : - { - RsTurtleFileDataItem *item = dynamic_cast(i) ; - if (item) - { + case RS_TURTLE_SUBTYPE_FILE_DATA : + { + RsTurtleFileDataItem *item = dynamic_cast(i) ; + if (item) + { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received file data for " << hash << " from peer " << virtual_peer_id << std::endl; + FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received file data for " << hash << " from peer " << virtual_peer_id << std::endl; #endif - getMultiplexer()->recvData(virtual_peer_id,hash,0,item->chunk_offset,item->chunk_size,item->chunk_data) ; + getMultiplexer()->recvData(virtual_peer_id,hash,0,item->chunk_offset,item->chunk_size,item->chunk_data) ; - item->chunk_data = NULL ; // this prevents deletion in the destructor of RsFileDataItem, because data will be deleted - // down _ft_server->getMultiplexer()->recvData()...in ftTransferModule::recvFileData - } - } - break ; + item->chunk_data = NULL ; // this prevents deletion in the destructor of RsFileDataItem, because data will be deleted + // down _ft_server->getMultiplexer()->recvData()...in ftTransferModule::recvFileData + } + } + break ; - case RS_TURTLE_SUBTYPE_FILE_MAP : - { - RsTurtleFileMapItem *item = dynamic_cast(i) ; - if (item) - { + case RS_TURTLE_SUBTYPE_FILE_MAP : + { + RsTurtleFileMapItem *item = dynamic_cast(i) ; + if (item) + { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received chunk map for hash " << hash << " from peer " << virtual_peer_id << std::endl; + FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received chunk map for hash " << hash << " from peer " << virtual_peer_id << std::endl; #endif - getMultiplexer()->recvChunkMap(virtual_peer_id,hash,item->compressed_map,direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ; - } - } - break ; + getMultiplexer()->recvChunkMap(virtual_peer_id,hash,item->compressed_map,direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ; + } + } + break ; - case RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST: - { - //RsTurtleFileMapRequestItem *item = dynamic_cast(i) ; + case RS_TURTLE_SUBTYPE_FILE_MAP_REQUEST: + { + //RsTurtleFileMapRequestItem *item = dynamic_cast(i) ; #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received chunkmap request for hash " << hash << " from peer " << virtual_peer_id << std::endl; + FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received chunkmap request for hash " << hash << " from peer " << virtual_peer_id << std::endl; #endif - getMultiplexer()->recvChunkMapRequest(virtual_peer_id,hash,direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ; - } - break ; + getMultiplexer()->recvChunkMapRequest(virtual_peer_id,hash,direction == RsTurtleGenericTunnelItem::DIRECTION_CLIENT) ; + } + break ; - case RS_TURTLE_SUBTYPE_CHUNK_CRC : - { - RsTurtleChunkCrcItem *item = dynamic_cast(i) ; - if (item) - { + case RS_TURTLE_SUBTYPE_CHUNK_CRC : + { + RsTurtleChunkCrcItem *item = dynamic_cast(i) ; + if (item) + { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received single chunk CRC for hash " << hash << " from peer " << virtual_peer_id << std::endl; + FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received single chunk CRC for hash " << hash << " from peer " << virtual_peer_id << std::endl; #endif - getMultiplexer()->recvSingleChunkCRC(virtual_peer_id,hash,item->chunk_number,item->check_sum) ; - } - } - break ; + getMultiplexer()->recvSingleChunkCRC(virtual_peer_id,hash,item->chunk_number,item->check_sum) ; + } + } + break ; - case RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST: - { - RsTurtleChunkCrcRequestItem *item = dynamic_cast(i) ; - if (item) - { + case RS_TURTLE_SUBTYPE_CHUNK_CRC_REQUEST: + { + RsTurtleChunkCrcRequestItem *item = dynamic_cast(i) ; + if (item) + { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received single chunk CRC request for hash " << hash << " from peer " << virtual_peer_id << std::endl; + FTSERVER_DEBUG() << "ftServer::receiveTurtleData(): received single chunk CRC request for hash " << hash << " from peer " << virtual_peer_id << std::endl; #endif - getMultiplexer()->recvSingleChunkCRCRequest(virtual_peer_id,hash,item->chunk_number) ; - } - } - break ; - default: - FTSERVER_ERROR() << "WARNING: Unknown packet type received: sub_id=" << reinterpret_cast(i->PacketSubType()) << ". Is somebody trying to poison you ?" << std::endl ; - } + getMultiplexer()->recvSingleChunkCRCRequest(virtual_peer_id,hash,item->chunk_number) ; + } + } + break ; + default: + FTSERVER_ERROR() << "WARNING: Unknown packet type received: sub_id=" << reinterpret_cast(i->PacketSubType()) << ". Is somebody trying to poison you ?" << std::endl ; + } } /* NB: The rsCore lock must be activated before calling this. @@ -1490,126 +1490,126 @@ void ftServer::receiveTurtleData(RsTurtleGenericTunnelItem *i, */ int ftServer::tick() { - bool moreToTick = false ; + bool moreToTick = false ; - if(handleIncoming()) - moreToTick = true; + if(handleIncoming()) + moreToTick = true; - static time_t last_law_priority_tasks_handling_time = 0 ; - time_t now = time(NULL) ; + static time_t last_law_priority_tasks_handling_time = 0 ; + time_t now = time(NULL) ; - if(last_law_priority_tasks_handling_time + FILE_TRANSFER_LOW_PRIORITY_TASKS_PERIOD < now) - { - last_law_priority_tasks_handling_time = now ; + if(last_law_priority_tasks_handling_time + FILE_TRANSFER_LOW_PRIORITY_TASKS_PERIOD < now) + { + last_law_priority_tasks_handling_time = now ; - mFtDataplex->deleteUnusedServers() ; - mFtDataplex->handlePendingCrcRequests() ; - mFtDataplex->dispatchReceivedChunkCheckSum() ; - } + mFtDataplex->deleteUnusedServers() ; + mFtDataplex->handlePendingCrcRequests() ; + mFtDataplex->dispatchReceivedChunkCheckSum() ; + } - return moreToTick; + return moreToTick; } int ftServer::handleIncoming() { - // now File Input. - int nhandled = 0 ; + // now File Input. + int nhandled = 0 ; - RsItem *item = NULL ; + RsItem *item = NULL ; - while(NULL != (item = recvItem())) - { - nhandled++ ; + while(NULL != (item = recvItem())) + { + nhandled++ ; - switch(item->PacketSubType()) - { - case RS_PKT_SUBTYPE_FT_DATA_REQUEST: - { - RsFileTransferDataRequestItem *f = dynamic_cast(item) ; - if (f) - { + switch(item->PacketSubType()) + { + case RS_PKT_SUBTYPE_FT_DATA_REQUEST: + { + RsFileTransferDataRequestItem *f = dynamic_cast(item) ; + if (f) + { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "ftServer::handleIncoming: received data request for hash " << f->file.hash << ", offset=" << f->fileoffset << ", chunk size=" << f->chunksize << std::endl; + FTSERVER_DEBUG() << "ftServer::handleIncoming: received data request for hash " << f->file.hash << ", offset=" << f->fileoffset << ", chunk size=" << f->chunksize << std::endl; #endif - mFtDataplex->recvDataRequest(f->PeerId(), f->file.hash, f->file.filesize, f->fileoffset, f->chunksize); - } - } - break ; + mFtDataplex->recvDataRequest(f->PeerId(), f->file.hash, f->file.filesize, f->fileoffset, f->chunksize); + } + } + break ; - case RS_PKT_SUBTYPE_FT_DATA: - { - RsFileTransferDataItem *f = dynamic_cast(item) ; - if (f) - { + case RS_PKT_SUBTYPE_FT_DATA: + { + RsFileTransferDataItem *f = dynamic_cast(item) ; + if (f) + { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "ftServer::handleIncoming: received data for hash " << f->fd.file.hash << ", offset=" << f->fd.file_offset << ", chunk size=" << f->fd.binData.bin_len << std::endl; + FTSERVER_DEBUG() << "ftServer::handleIncoming: received data for hash " << f->fd.file.hash << ", offset=" << f->fd.file_offset << ", chunk size=" << f->fd.binData.bin_len << std::endl; #endif - mFtDataplex->recvData(f->PeerId(), f->fd.file.hash, f->fd.file.filesize, f->fd.file_offset, f->fd.binData.bin_len, f->fd.binData.bin_data); + mFtDataplex->recvData(f->PeerId(), f->fd.file.hash, f->fd.file.filesize, f->fd.file_offset, f->fd.binData.bin_len, f->fd.binData.bin_data); - /* we've stolen the data part -> so blank before delete - */ - f->fd.binData.TlvShallowClear(); - } - } - break ; + /* we've stolen the data part -> so blank before delete + */ + f->fd.binData.TlvShallowClear(); + } + } + break ; - case RS_PKT_SUBTYPE_FT_CHUNK_MAP_REQUEST: - { - RsFileTransferChunkMapRequestItem *f = dynamic_cast(item) ; - if (f) - { + case RS_PKT_SUBTYPE_FT_CHUNK_MAP_REQUEST: + { + RsFileTransferChunkMapRequestItem *f = dynamic_cast(item) ; + if (f) + { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "ftServer::handleIncoming: received chunkmap request for hash " << f->hash << ", client=" << f->is_client << std::endl; + FTSERVER_DEBUG() << "ftServer::handleIncoming: received chunkmap request for hash " << f->hash << ", client=" << f->is_client << std::endl; #endif - mFtDataplex->recvChunkMapRequest(f->PeerId(), f->hash,f->is_client) ; - } - } - break ; + mFtDataplex->recvChunkMapRequest(f->PeerId(), f->hash,f->is_client) ; + } + } + break ; - case RS_PKT_SUBTYPE_FT_CHUNK_MAP: - { - RsFileTransferChunkMapItem *f = dynamic_cast(item) ; - if (f) - { + case RS_PKT_SUBTYPE_FT_CHUNK_MAP: + { + RsFileTransferChunkMapItem *f = dynamic_cast(item) ; + if (f) + { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "ftServer::handleIncoming: received chunkmap for hash " << f->hash << ", client=" << f->is_client << /*", map=" << f->compressed_map <<*/ std::endl; + FTSERVER_DEBUG() << "ftServer::handleIncoming: received chunkmap for hash " << f->hash << ", client=" << f->is_client << /*", map=" << f->compressed_map <<*/ std::endl; #endif - mFtDataplex->recvChunkMap(f->PeerId(), f->hash,f->compressed_map,f->is_client) ; - } - } - break ; + mFtDataplex->recvChunkMap(f->PeerId(), f->hash,f->compressed_map,f->is_client) ; + } + } + break ; - case RS_PKT_SUBTYPE_FT_CHUNK_CRC_REQUEST: - { - RsFileTransferSingleChunkCrcRequestItem *f = dynamic_cast(item) ; - if (f) - { + case RS_PKT_SUBTYPE_FT_CHUNK_CRC_REQUEST: + { + RsFileTransferSingleChunkCrcRequestItem *f = dynamic_cast(item) ; + if (f) + { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "ftServer::handleIncoming: received single chunk crc req for hash " << f->hash << ", chunk number=" << f->chunk_number << std::endl; + FTSERVER_DEBUG() << "ftServer::handleIncoming: received single chunk crc req for hash " << f->hash << ", chunk number=" << f->chunk_number << std::endl; #endif - mFtDataplex->recvSingleChunkCRCRequest(f->PeerId(), f->hash,f->chunk_number) ; - } - } - break ; + mFtDataplex->recvSingleChunkCRCRequest(f->PeerId(), f->hash,f->chunk_number) ; + } + } + break ; - case RS_PKT_SUBTYPE_FT_CHUNK_CRC: - { - RsFileTransferSingleChunkCrcItem *f = dynamic_cast(item) ; - if (f) - { + case RS_PKT_SUBTYPE_FT_CHUNK_CRC: + { + RsFileTransferSingleChunkCrcItem *f = dynamic_cast(item) ; + if (f) + { #ifdef SERVER_DEBUG - FTSERVER_DEBUG() << "ftServer::handleIncoming: received single chunk crc req for hash " << f->hash << ", chunk number=" << f->chunk_number << ", checksum = " << f->check_sum << std::endl; + FTSERVER_DEBUG() << "ftServer::handleIncoming: received single chunk crc req for hash " << f->hash << ", chunk number=" << f->chunk_number << ", checksum = " << f->check_sum << std::endl; #endif - mFtDataplex->recvSingleChunkCRC(f->PeerId(), f->hash,f->chunk_number,f->check_sum); - } - } - break ; - } + mFtDataplex->recvSingleChunkCRC(f->PeerId(), f->hash,f->chunk_number,f->check_sum); + } + } + break ; + } - delete item ; - } + delete item ; + } - return nhandled; + return nhandled; } /********************************** @@ -1617,15 +1617,15 @@ int ftServer::handleIncoming() ********************************** *********************************/ - /***************************** CONFIG ****************************/ +/***************************** CONFIG ****************************/ bool ftServer::addConfiguration(p3ConfigMgr *cfgmgr) { - /* add all the subbits to config mgr */ - cfgmgr->addConfiguration("ft_database.cfg", mFileDatabase); - cfgmgr->addConfiguration("ft_extra.cfg", mFtExtra); - cfgmgr->addConfiguration("ft_transfers.cfg", mFtController); + /* add all the subbits to config mgr */ + cfgmgr->addConfiguration("ft_database.cfg", mFileDatabase); + cfgmgr->addConfiguration("ft_extra.cfg", mFtExtra); + cfgmgr->addConfiguration("ft_transfers.cfg", mFtController); - return true; + return true; } From 86536491321e6fb04558b442e6ad0470e41cd590 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Thu, 3 Nov 2016 20:26:35 +0100 Subject: [PATCH 34/52] fixed two bugs in ShareManager popup menu --- retroshare-gui/src/gui/ShareManager.cpp | 17 +++++++++++++---- retroshare-gui/src/gui/ShareManager.h | 4 ++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/retroshare-gui/src/gui/ShareManager.cpp b/retroshare-gui/src/gui/ShareManager.cpp index 9201e4696..213d254cb 100644 --- a/retroshare-gui/src/gui/ShareManager.cpp +++ b/retroshare-gui/src/gui/ShareManager.cpp @@ -69,7 +69,7 @@ ShareManager::ShareManager() connect(ui.closeButton, SIGNAL(clicked()), this, SLOT(applyAndClose())); connect(ui.cancelButton, SIGNAL(clicked()), this, SLOT(cancel())); - connect(ui.shareddirList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(shareddirListCostumPopupMenu(QPoint))); + connect(ui.shareddirList, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(shareddirListCustomPopupMenu(QPoint))); connect(ui.shareddirList, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(doubleClickedCell(int,int))); connect(ui.shareddirList, SIGNAL(cellChanged(int,int)), this, SLOT(handleCellChange(int,int))); @@ -106,6 +106,14 @@ void ShareManager::handleCellChange(int row,int column) } } +void ShareManager::editShareDirectory() +{ + QTableWidget *listWidget = ui.shareddirList; + int row = listWidget -> currentRow(); + + doubleClickedCell(row,COLUMN_PATH) ; +} + void ShareManager::doubleClickedCell(int row,int column) { if(column == COLUMN_PATH) @@ -158,7 +166,7 @@ void ShareManager::applyAndClose() close() ; } -void ShareManager::shareddirListCostumPopupMenu( QPoint /*point*/ ) +void ShareManager::shareddirListCustomPopupMenu( QPoint /*point*/ ) { QMenu contextMnu( this ); @@ -300,9 +308,10 @@ void ShareManager::removeShareDirectory() { if ((QMessageBox::question(this, tr("Warning!"),tr("Do you really want to stop sharing this directory ?"),QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes))== QMessageBox::Yes) { - for(uint32_t i=row;i+1 Date: Thu, 3 Nov 2016 20:31:47 +0100 Subject: [PATCH 35/52] removed warning in ftserver for rejected non encrypted tunnels --- libretroshare/src/ft/ftserver.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index f8f6821ae..49644ba68 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -596,9 +596,11 @@ bool ftServer::handleTunnelRequest(const RsFileHash& hash,const RsPeerId& peer_i } } - if(mFtController->defaultEncryptionPolicy() == RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT && hash == real_hash) + if(found && mFtController->defaultEncryptionPolicy() == RS_FILE_CTRL_ENCRYPTION_POLICY_STRICT && hash == real_hash) { +#ifdef SERVER_DEBUG std::cerr << "(WW) rejecting file transfer for hash " << hash << " because the hash is not encrypted and encryption policy requires it." << std::endl; +#endif return false ; } From 8dacb22049d9748e27462712248a81b65bb9507c Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 3 Nov 2016 22:32:27 +0100 Subject: [PATCH 36/52] reducing linear cost of allocateNewIndex to constant. Should improve huge lags when receiving big file lists for the first time --- .../src/file_sharing/dir_hierarchy.cc | 57 +++++++++++-------- .../src/file_sharing/dir_hierarchy.h | 5 ++ libretroshare/src/file_sharing/p3filelists.cc | 4 +- 3 files changed, 39 insertions(+), 27 deletions(-) diff --git a/libretroshare/src/file_sharing/dir_hierarchy.cc b/libretroshare/src/file_sharing/dir_hierarchy.cc index 07e395455..54bd13cd1 100644 --- a/libretroshare/src/file_sharing/dir_hierarchy.cc +++ b/libretroshare/src/file_sharing/dir_hierarchy.cc @@ -299,8 +299,7 @@ bool InternalFileHierarchyStorage::updateSubFilesList(const DirectoryStorage::En std::cerr << "[directory storage] removing non existing file " << f.file_name << " at index " << d.subfiles[i] << std::endl; #endif - delete mNodes[d.subfiles[i]] ; - mNodes[d.subfiles[i]] = NULL ; + deleteNode(d.subfiles[i]) ; d.subfiles[i] = d.subfiles[d.subfiles.size()-1] ; d.subfiles.pop_back(); @@ -374,23 +373,29 @@ bool InternalFileHierarchyStorage::updateFile(const DirectoryStorage::EntryIndex return true; } +void InternalFileHierarchyStorage::deleteNode(uint32_t index) +{ + if(mNodes[index] != NULL) + { + delete mNodes[index] ; + mFreeNodes.push_back(index) ; + mNodes[index] = NULL ; + } +} + DirectoryStorage::EntryIndex InternalFileHierarchyStorage::allocateNewIndex() { - int found = -1; - for(uint32_t j=0;j& subdirs_hash,const std::vector& subfiles_array) @@ -534,8 +539,7 @@ bool InternalFileHierarchyStorage::updateDirEntry(const DirectoryStorage::EntryI std::cerr << "(EE) Cannot delete node of index " << it->second << " because it is not a file. Inconsistency error!" << std::endl; continue ; } - delete mNodes[it->second] ; - mNodes[it->second] = NULL ; + deleteNode(it->second) ; } // now update row and parent index for all subnodes @@ -749,6 +753,8 @@ bool InternalFileHierarchyStorage::check(std::string& error_string) // checks co std::vector hits(mNodes.size(),0) ; // count hits of children. Should be 1 for all in the end. Otherwise there's an error. hits[0] = 1 ; // because 0 is never the child of anyone + mFreeNodes.clear(); + for(uint32_t i=0;itype() == FileStorageNode::TYPE_DIR) { @@ -796,13 +802,15 @@ bool InternalFileHierarchyStorage::check(std::string& error_string) // checks co } } } + else if(mNodes[i] == NULL) + mFreeNodes.push_back(i) ; for(uint32_t i=0;i mFreeNodes ; // keeps a list of free nodes in order to make insert effcieint std::vector mNodes;// uses pointers to keep information about valid/invalid objects. void compress() ; // use empty space in the vector, mostly due to deleted entries. This is a complicated operation, mostly due to @@ -159,6 +160,10 @@ private: DirectoryStorage::EntryIndex allocateNewIndex(); + // Deletes an existing entry in mNodes, and keeps record of the indices that get freed. + + void deleteNode(DirectoryStorage::EntryIndex); + // Removes the given subdirectory from the parent node and all its pendign subdirs. Files are kept, and will go during the cleaning // phase. That allows to keep file information when moving them around. diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index 21875efad..211eca2e7 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -543,7 +543,7 @@ uint32_t p3FileDatabase::locked_getFriendIndex(const RsPeerId& pid) mUpdateFlags |= P3FILELISTS_UPDATE_FLAG_REMOTE_MAP_CHANGED ; #ifdef DEBUG_P3FILELISTS - P3FILELISTS_DEBUG() << " adding missing remote dir entry for friend " << *it << ", with index " << friend_index << std::endl; + P3FILELISTS_DEBUG() << " adding missing remote dir entry for friend " << pid << ", with index " << it->second << std::endl; #endif } @@ -570,7 +570,7 @@ uint32_t p3FileDatabase::locked_getFriendIndex(const RsPeerId& pid) mUpdateFlags |= P3FILELISTS_UPDATE_FLAG_REMOTE_MAP_CHANGED ; #ifdef DEBUG_P3FILELISTS - P3FILELISTS_DEBUG() << " adding missing remote dir entry for friend " << *it << ", with index " << friend_index << std::endl; + P3FILELISTS_DEBUG() << " adding missing remote dir entry for friend " << pid << ", with index " << it->second << std::endl; #endif } From 30860b8f1a696323fa15b5d633b9b72393ffb1c7 Mon Sep 17 00:00:00 2001 From: mr-alice Date: Fri, 4 Nov 2016 13:46:20 +0100 Subject: [PATCH 37/52] removed ^M that polluted unittests.pro --- tests/unittests/unittests.pro | 736 +++++++++++++++++----------------- 1 file changed, 368 insertions(+), 368 deletions(-) diff --git a/tests/unittests/unittests.pro b/tests/unittests/unittests.pro index c72520344..db4a881d7 100644 --- a/tests/unittests/unittests.pro +++ b/tests/unittests/unittests.pro @@ -1,156 +1,156 @@ !include("../../retroshare.pri"): error("Could not include file ../../retroshare.pri") -QT += network xml script -CONFIG += bitdht - -CONFIG += gxs debug - -gxs { - DEFINES += RS_ENABLE_GXS -} - -TEMPLATE = app -TARGET = unittests - -OPENPGPSDK_DIR = ../../openpgpsdk/src -INCLUDEPATH *= $${OPENPGPSDK_DIR} ../openpgpsdk - -# it is impossible to use precompield googletest lib -# because googletest must be compiled with same compiler flags as the tests! -!exists(../googletest/googletest/src/gtest-all.cc){ - message(trying to git clone googletest...) - !system(git clone https://github.com/google/googletest.git ../googletest){ - error(Could not git clone googletest files. You can manually download them to /tests/googletest) - } -} - -INCLUDEPATH += \ - ../googletest/googletest/include \ - ../googletest/googletest - -SOURCES += ../googletest/googletest/src/gtest-all.cc - -################################# Linux ########################################## -# Put lib dir in QMAKE_LFLAGS so it appears before -L/usr/lib -linux-* { - #CONFIG += version_detail_bash_script - QMAKE_CXXFLAGS *= -D_FILE_OFFSET_BITS=64 - - PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a - PRE_TARGETDEPS *= ../../openpgpsdk/src/lib/libops.a - - LIBS += ../../libretroshare/src/lib/libretroshare.a - LIBS += ../librssimulator/lib/librssimulator.a - LIBS += ../../openpgpsdk/src/lib/libops.a -lbz2 - LIBS += -lssl -lupnp -lixml -lXss -lgnome-keyring - LIBS *= -lcrypto -ldl -lX11 -lz -lpthread - - #LIBS += ../../supportlibs/pegmarkdown/lib/libpegmarkdown.a - - contains(CONFIG, NO_SQLCIPHER) { - DEFINES *= NO_SQLCIPHER - PKGCONFIG *= sqlite3 - } else { - # We need a explicit path here, to force using the home version of sqlite3 that really encrypts the database. - - SQLCIPHER_OK = $$system(pkg-config --exists sqlcipher && echo yes) - isEmpty(SQLCIPHER_OK) { - # We need a explicit path here, to force using the home version of sqlite3 that really encrypts the database. - - ! exists(../../../lib/sqlcipher/.libs/libsqlcipher.a) { - message(../../../lib/sqlcipher/.libs/libsqlcipher.a does not exist) - error(Please fix this and try again. Will stop now.) - } - - LIBS += ../../../lib/sqlcipher/.libs/libsqlcipher.a - INCLUDEPATH += ../../../lib/sqlcipher/src/ - INCLUDEPATH += ../../../lib/sqlcipher/tsrc/ - } else { - LIBS += -lsqlcipher - } - } - - - LIBS *= -lglib-2.0 - LIBS *= -rdynamic - DEFINES *= HAVE_XSS # for idle time, libx screensaver extensions - DEFINES *= HAS_GNOME_KEYRING -} - -linux-g++ { - OBJECTS_DIR = temp/linux-g++/obj -} - -linux-g++-64 { - OBJECTS_DIR = temp/linux-g++-64/obj -} - -#################### Cross compilation for windows under Linux ################### - -win32-x-g++ { - OBJECTS_DIR = temp/win32-x-g++/obj - - LIBS += ../../libretroshare/src/lib.win32xgcc/libretroshare.a - LIBS += ../../../../lib/win32-x-g++-v0.5/libssl.a - LIBS += ../../../../lib/win32-x-g++-v0.5/libcrypto.a - LIBS += ../../../../lib/win32-x-g++-v0.5/libgpgme.dll.a - LIBS += ../../../../lib/win32-x-g++-v0.5/libminiupnpc.a - LIBS += ../../../../lib/win32-x-g++-v0.5/libz.a - LIBS += -L${HOME}/.wine/drive_c/pthreads/lib -lpthreadGCE2 - LIBS += -lQtUiTools - LIBS += -lws2_32 -luuid -lole32 -liphlpapi -lcrypt32 -gdi32 - LIBS += -lole32 -lwinmm - - DEFINES *= WINDOWS_SYS WIN32 WIN32_CROSS_UBUNTU - - INCLUDEPATH += ../../../../gpgme-1.1.8/src/ - INCLUDEPATH += ../../../../libgpg-error-1.7/src/ - - RC_FILE = gui/images/retroshare_win.rc -} - -#################################### Windows ##################################### - -win32 { - # Switch on extra warnings - QMAKE_CFLAGS += -Wextra - QMAKE_CXXFLAGS += -Wextra - +QT += network xml script +CONFIG += bitdht + +CONFIG += gxs debug + +gxs { + DEFINES += RS_ENABLE_GXS +} + +TEMPLATE = app +TARGET = unittests + +OPENPGPSDK_DIR = ../../openpgpsdk/src +INCLUDEPATH *= $${OPENPGPSDK_DIR} ../openpgpsdk + +# it is impossible to use precompield googletest lib +# because googletest must be compiled with same compiler flags as the tests! +!exists(../googletest/googletest/src/gtest-all.cc){ + message(trying to git clone googletest...) + !system(git clone https://github.com/google/googletest.git ../googletest){ + error(Could not git clone googletest files. You can manually download them to /tests/googletest) + } +} + +INCLUDEPATH += \ + ../googletest/googletest/include \ + ../googletest/googletest + +SOURCES += ../googletest/googletest/src/gtest-all.cc + +################################# Linux ########################################## +# Put lib dir in QMAKE_LFLAGS so it appears before -L/usr/lib +linux-* { + #CONFIG += version_detail_bash_script + QMAKE_CXXFLAGS *= -D_FILE_OFFSET_BITS=64 + + PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a + PRE_TARGETDEPS *= ../../openpgpsdk/src/lib/libops.a + + LIBS += ../../libretroshare/src/lib/libretroshare.a + LIBS += ../librssimulator/lib/librssimulator.a + LIBS += ../../openpgpsdk/src/lib/libops.a -lbz2 + LIBS += -lssl -lupnp -lixml -lXss -lgnome-keyring + LIBS *= -lcrypto -ldl -lX11 -lz -lpthread + + #LIBS += ../../supportlibs/pegmarkdown/lib/libpegmarkdown.a + + contains(CONFIG, NO_SQLCIPHER) { + DEFINES *= NO_SQLCIPHER + PKGCONFIG *= sqlite3 + } else { + # We need a explicit path here, to force using the home version of sqlite3 that really encrypts the database. + + SQLCIPHER_OK = $$system(pkg-config --exists sqlcipher && echo yes) + isEmpty(SQLCIPHER_OK) { + # We need a explicit path here, to force using the home version of sqlite3 that really encrypts the database. + + ! exists(../../../lib/sqlcipher/.libs/libsqlcipher.a) { + message(../../../lib/sqlcipher/.libs/libsqlcipher.a does not exist) + error(Please fix this and try again. Will stop now.) + } + + LIBS += ../../../lib/sqlcipher/.libs/libsqlcipher.a + INCLUDEPATH += ../../../lib/sqlcipher/src/ + INCLUDEPATH += ../../../lib/sqlcipher/tsrc/ + } else { + LIBS += -lsqlcipher + } + } + + + LIBS *= -lglib-2.0 + LIBS *= -rdynamic + DEFINES *= HAVE_XSS # for idle time, libx screensaver extensions + DEFINES *= HAS_GNOME_KEYRING +} + +linux-g++ { + OBJECTS_DIR = temp/linux-g++/obj +} + +linux-g++-64 { + OBJECTS_DIR = temp/linux-g++-64/obj +} + +#################### Cross compilation for windows under Linux ################### + +win32-x-g++ { + OBJECTS_DIR = temp/win32-x-g++/obj + + LIBS += ../../libretroshare/src/lib.win32xgcc/libretroshare.a + LIBS += ../../../../lib/win32-x-g++-v0.5/libssl.a + LIBS += ../../../../lib/win32-x-g++-v0.5/libcrypto.a + LIBS += ../../../../lib/win32-x-g++-v0.5/libgpgme.dll.a + LIBS += ../../../../lib/win32-x-g++-v0.5/libminiupnpc.a + LIBS += ../../../../lib/win32-x-g++-v0.5/libz.a + LIBS += -L${HOME}/.wine/drive_c/pthreads/lib -lpthreadGCE2 + LIBS += -lQtUiTools + LIBS += -lws2_32 -luuid -lole32 -liphlpapi -lcrypt32 -gdi32 + LIBS += -lole32 -lwinmm + + DEFINES *= WINDOWS_SYS WIN32 WIN32_CROSS_UBUNTU + + INCLUDEPATH += ../../../../gpgme-1.1.8/src/ + INCLUDEPATH += ../../../../libgpg-error-1.7/src/ + + RC_FILE = gui/images/retroshare_win.rc +} + +#################################### Windows ##################################### + +win32 { + # Switch on extra warnings + QMAKE_CFLAGS += -Wextra + QMAKE_CXXFLAGS += -Wextra + # solve linker warnings because of the order of the libraries QMAKE_LFLAGS += -Wl,--start-group - # Switch off optimization for release version - QMAKE_CXXFLAGS_RELEASE -= -O2 - QMAKE_CXXFLAGS_RELEASE += -O0 - QMAKE_CFLAGS_RELEASE -= -O2 - QMAKE_CFLAGS_RELEASE += -O0 - - # Switch on optimization for debug version - #QMAKE_CXXFLAGS_DEBUG += -O2 - #QMAKE_CFLAGS_DEBUG += -O2 - - OBJECTS_DIR = temp/obj - #LIBS += -L"D/Qt/2009.03/qt/plugins/imageformats" - #QTPLUGIN += qjpeg - - PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a - PRE_TARGETDEPS *= ../librssimulator/lib/librssimulator.a - PRE_TARGETDEPS *= ../../openpgpsdk/src/lib/libops.a - + # Switch off optimization for release version + QMAKE_CXXFLAGS_RELEASE -= -O2 + QMAKE_CXXFLAGS_RELEASE += -O0 + QMAKE_CFLAGS_RELEASE -= -O2 + QMAKE_CFLAGS_RELEASE += -O0 + + # Switch on optimization for debug version + #QMAKE_CXXFLAGS_DEBUG += -O2 + #QMAKE_CFLAGS_DEBUG += -O2 + + OBJECTS_DIR = temp/obj + #LIBS += -L"D/Qt/2009.03/qt/plugins/imageformats" + #QTPLUGIN += qjpeg + + PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a + PRE_TARGETDEPS *= ../librssimulator/lib/librssimulator.a + PRE_TARGETDEPS *= ../../openpgpsdk/src/lib/libops.a + for(lib, LIB_DIR):LIBS += -L"$$lib" for(bin, BIN_DIR):LIBS += -L"$$bin" - LIBS += ../../libretroshare/src/lib/libretroshare.a + LIBS += ../../libretroshare/src/lib/libretroshare.a LIBS += ../librssimulator/lib/librssimulator.a - LIBS += ../../openpgpsdk/src/lib/libops.a -lbz2 - LIBS += -L"$$PWD/../../../lib" - - LIBS += -lssl -lcrypto -lpthread -lminiupnpc -lz - LIBS += -luuid -lole32 -liphlpapi -lcrypt32 -lgdi32 + LIBS += ../../openpgpsdk/src/lib/libops.a -lbz2 + LIBS += -L"$$PWD/../../../lib" + + LIBS += -lssl -lcrypto -lpthread -lminiupnpc -lz + LIBS += -luuid -lole32 -liphlpapi -lcrypt32 -lgdi32 LIBS += -lwinmm - - DEFINES *= WINDOWS_SYS WIN32_LEAN_AND_MEAN _USE_32BIT_TIME_T - + + DEFINES *= WINDOWS_SYS WIN32_LEAN_AND_MEAN _USE_32BIT_TIME_T + # create lib directory message(CHK_DIR_EXISTS=$(CHK_DIR_EXISTS)) message(MKDIR=$(MKDIR)) @@ -166,231 +166,231 @@ win32 { # Qt 4 QMAKE_RC += --include-dir=$$_PRO_FILE_PWD_/../../libretroshare/src } -} - -##################################### MacOS ###################################### - -macx { - # ENABLE THIS OPTION FOR Univeral Binary BUILD. - CONFIG += ppc x86 - QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.4 - - CONFIG += version_detail_bash_script - LIBS += ../../libretroshare/src/lib/libretroshare.a - LIBS += ../librssimulator/lib/librssimulator.a - LIBS += ../../openpgpsdk/src/lib/libops.a -lbz2 - LIBS += -lssl -lcrypto -lz - #LIBS += -lssl -lcrypto -lz -lgpgme -lgpg-error -lassuan - LIBS += ../../../miniupnpc-1.0/libminiupnpc.a - LIBS += -framework CoreFoundation - LIBS += -framework Security - - gxs { - LIBS += ../../supportlibs/pegmarkdown/lib/libpegmarkdown.a - - LIBS += ../../../lib/libsqlcipher.a - #LIBS += -lsqlite3 - - } - - - INCLUDEPATH += . - #DEFINES* = MAC_IDLE # for idle feature - CONFIG -= uitools - - -} - -##################################### FreeBSD ###################################### - -freebsd-* { - INCLUDEPATH *= /usr/local/include/gpgme - LIBS *= ../../libretroshare/src/lib/libretroshare.a - LIBS *= ../librssimulator/lib/librssimulator.a - LIBS *= -lssl - LIBS *= -lgpgme - LIBS *= -lupnp - LIBS *= -lgnome-keyring - PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a - - gxs { - LIBS += ../../supportlibs/pegmarkdown/lib/libpegmarkdown.a - LIBS += -lsqlite3 - } - -} - -##################################### OpenBSD ###################################### - -openbsd-* { - INCLUDEPATH *= /usr/local/include - - PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a - PRE_TARGETDEPS *= ../../openpgpsdk/src/lib/libops.a - - LIBS *= ../../libretroshare/src/lib/libretroshare.a - LIBS *= ../librssimulator/lib/librssimulator.a - LIBS *= ../../openpgpsdk/src/lib/libops.a -lbz2 - LIBS *= -lssl -lcrypto - LIBS *= -lgpgme - LIBS *= -lupnp - LIBS *= -lgnome-keyring - PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a - - gxs { - LIBS += ../../supportlibs/pegmarkdown/lib/libpegmarkdown.a - LIBS += -lsqlite3 - } - - LIBS *= -rdynamic -} - - - -############################## Common stuff ###################################### - -# On Linux systems that alredy have libssl and libcrypto it is advisable -# to rename the patched version of SSL to something like libsslxpgp.a and libcryptoxpg.a - -# ########################################### - -bitdht { - LIBS += ../../libbitdht/src/lib/libbitdht.a - PRE_TARGETDEPS *= ../../libbitdht/src/lib/libbitdht.a -} - -win32 { -# must be added after bitdht - LIBS += -lws2_32 -} - -DEPENDPATH += . \ - -INCLUDEPATH += ../../libretroshare/src/ -INCLUDEPATH += ../librssimulator/ - -SOURCES += unittests.cc \ - -################################## Crypto ################################## +} + +##################################### MacOS ###################################### + +macx { + # ENABLE THIS OPTION FOR Univeral Binary BUILD. + CONFIG += ppc x86 + QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.4 + + CONFIG += version_detail_bash_script + LIBS += ../../libretroshare/src/lib/libretroshare.a + LIBS += ../librssimulator/lib/librssimulator.a + LIBS += ../../openpgpsdk/src/lib/libops.a -lbz2 + LIBS += -lssl -lcrypto -lz + #LIBS += -lssl -lcrypto -lz -lgpgme -lgpg-error -lassuan + LIBS += ../../../miniupnpc-1.0/libminiupnpc.a + LIBS += -framework CoreFoundation + LIBS += -framework Security + + gxs { + LIBS += ../../supportlibs/pegmarkdown/lib/libpegmarkdown.a + + LIBS += ../../../lib/libsqlcipher.a + #LIBS += -lsqlite3 + + } + + + INCLUDEPATH += . + #DEFINES* = MAC_IDLE # for idle feature + CONFIG -= uitools + + +} + +##################################### FreeBSD ###################################### + +freebsd-* { + INCLUDEPATH *= /usr/local/include/gpgme + LIBS *= ../../libretroshare/src/lib/libretroshare.a + LIBS *= ../librssimulator/lib/librssimulator.a + LIBS *= -lssl + LIBS *= -lgpgme + LIBS *= -lupnp + LIBS *= -lgnome-keyring + PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a + + gxs { + LIBS += ../../supportlibs/pegmarkdown/lib/libpegmarkdown.a + LIBS += -lsqlite3 + } + +} + +##################################### OpenBSD ###################################### + +openbsd-* { + INCLUDEPATH *= /usr/local/include + + PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a + PRE_TARGETDEPS *= ../../openpgpsdk/src/lib/libops.a + + LIBS *= ../../libretroshare/src/lib/libretroshare.a + LIBS *= ../librssimulator/lib/librssimulator.a + LIBS *= ../../openpgpsdk/src/lib/libops.a -lbz2 + LIBS *= -lssl -lcrypto + LIBS *= -lgpgme + LIBS *= -lupnp + LIBS *= -lgnome-keyring + PRE_TARGETDEPS *= ../../libretroshare/src/lib/libretroshare.a + + gxs { + LIBS += ../../supportlibs/pegmarkdown/lib/libpegmarkdown.a + LIBS += -lsqlite3 + } + + LIBS *= -rdynamic +} + + + +############################## Common stuff ###################################### + +# On Linux systems that alredy have libssl and libcrypto it is advisable +# to rename the patched version of SSL to something like libsslxpgp.a and libcryptoxpg.a + +# ########################################### + +bitdht { + LIBS += ../../libbitdht/src/lib/libbitdht.a + PRE_TARGETDEPS *= ../../libbitdht/src/lib/libbitdht.a +} + +win32 { +# must be added after bitdht + LIBS += -lws2_32 +} + +DEPENDPATH += . \ + +INCLUDEPATH += ../../libretroshare/src/ +INCLUDEPATH += ../librssimulator/ + +SOURCES += unittests.cc \ + +################################## Crypto ################################## SOURCES += libretroshare/crypto/chacha20_test.cc -################################ Serialiser ################################ -HEADERS += libretroshare/serialiser/support.h \ - libretroshare/serialiser/rstlvutil.h \ - -SOURCES += libretroshare/serialiser/rsturtleitem_test.cc \ - libretroshare/serialiser/rsbaseitem_test.cc \ - libretroshare/serialiser/rsgxsupdateitem_test.cc \ - libretroshare/serialiser/rsmsgitem_test.cc \ - libretroshare/serialiser/rsstatusitem_test.cc \ - libretroshare/serialiser/rsnxsitems_test.cc \ - libretroshare/serialiser/rsgxsiditem_test.cc \ -# libretroshare/serialiser/rsphotoitem_test.cc \ - libretroshare/serialiser/tlvbase_test2.cc \ - libretroshare/serialiser/tlvrandom_test.cc \ - libretroshare/serialiser/tlvbase_test.cc \ - libretroshare/serialiser/tlvstack_test.cc \ - libretroshare/serialiser/tlvitems_test.cc \ -# libretroshare/serialiser/rsgrouteritem_test.cc \ - libretroshare/serialiser/tlvtypes_test.cc \ - libretroshare/serialiser/tlvkey_test.cc \ - libretroshare/serialiser/support.cc \ - libretroshare/serialiser/rstlvutil.cc \ - -# Still to convert these. -# libretroshare/serialiser/rsconfigitem_test.cc \ -# libretroshare/serialiser/rsgrouteritem_test.cc \ - - -################################## GXS ##################################### - -HEADERS += libretroshare/gxs/common/data_support.h \ - -SOURCES += libretroshare/gxs/common/data_support.cc \ - -HEADERS += libretroshare/gxs/nxs_test/nxsdummyservices.h \ - libretroshare/gxs/nxs_test/nxsgrptestscenario.h \ - libretroshare/gxs/nxs_test/nxsmsgtestscenario.h \ - libretroshare/gxs/nxs_test/nxsgrpsync_test.h \ - libretroshare/gxs/nxs_test/nxsmsgsync_test.h \ - libretroshare/gxs/nxs_test/nxstesthub.h \ - libretroshare/gxs/nxs_test/nxstestscenario.h \ - libretroshare/gxs/nxs_test/nxsgrpsyncdelayed.h - -SOURCES += libretroshare/gxs/nxs_test/nxsdummyservices.cc \ - libretroshare/gxs/nxs_test/nxsgrptestscenario.cc \ - libretroshare/gxs/nxs_test/nxsmsgtestscenario.cc \ - libretroshare/gxs/nxs_test/nxstesthub.cc \ - libretroshare/gxs/nxs_test/rsgxsnetservice_test.cc \ - libretroshare/gxs/nxs_test/nxsmsgsync_test.cc \ - libretroshare/gxs/nxs_test/nxsgrpsync_test.cc \ - libretroshare/gxs/nxs_test/nxsgrpsyncdelayed.cc - -HEADERS += libretroshare/gxs/gen_exchange/genexchangetester.h \ - libretroshare/gxs/gen_exchange/gxspublishmsgtest.h \ - libretroshare/gxs/gen_exchange/genexchangetestservice.h \ - libretroshare/gxs/gen_exchange/gxspublishgrouptest.h \ - libretroshare/gxs/gen_exchange/rsdummyservices.h \ - libretroshare/gxs/gen_exchange/gxsteststats.cpp - -# libretroshare/gxs/gen_exchange/gxsmsgrelatedtest.h \ - -SOURCES += libretroshare/gxs/gen_exchange/gxspublishgrouptest.cc \ - libretroshare/gxs/gen_exchange/gxsteststats.cpp \ - libretroshare/gxs/gen_exchange/gxspublishmsgtest.cc \ - libretroshare/gxs/gen_exchange/rsdummyservices.cc \ - libretroshare/gxs/gen_exchange/rsgenexchange_test.cc \ - libretroshare/gxs/gen_exchange/genexchangetester.cc \ - libretroshare/gxs/gen_exchange/genexchangetestservice.cc \ - -SOURCES += libretroshare/gxs/security/gxssecurity_test.cc - -# libretroshare/gxs/gen_exchange/gxsmsgrelatedtest.cc \ - -HEADERS += libretroshare/gxs/data_service/rsdataservice_test.h \ - -SOURCES += libretroshare/gxs/data_service/rsdataservice_test.cc \ - libretroshare/gxs/data_service/rsgxsdata_test.cc \ - - -################################ dbase ##################################### - - -#SOURCES += libretroshare/dbase/fisavetest.cc \ -# libretroshare/dbase/fitest2.cc \ -# libretroshare/dbase/searchtest.cc \ - -# libretroshare/dbase/ficachetest.cc \ -# libretroshare/dbase/fimontest.cc \ - - -############################### services ################################### - -SOURCES += libretroshare/services/status/status_test.cc \ - -############################### gxs ######################################## - -HEADERS += libretroshare/services/gxs/rsgxstestitems.h \ - libretroshare/services/gxs/gxstestservice.h \ - libretroshare/services/gxs/GxsIsolatedServiceTester.h \ - libretroshare/services/gxs/GxsPeerNode.h \ - libretroshare/services/gxs/GxsPairServiceTester.h \ - libretroshare/services/gxs/FakePgpAuxUtils.h \ - -# libretroshare/services/gxs/RsGxsNetServiceTester.h \ - -SOURCES += libretroshare/services/gxs/rsgxstestitems.cc \ - libretroshare/services/gxs/gxstestservice.cc \ - libretroshare/services/gxs/GxsIsolatedServiceTester.cc \ - libretroshare/services/gxs/GxsPeerNode.cc \ - libretroshare/services/gxs/GxsPairServiceTester.cc \ - libretroshare/services/gxs/FakePgpAuxUtils.cc \ - libretroshare/services/gxs/nxsbasic_test.cc \ - libretroshare/services/gxs/nxspair_tests.cc \ - libretroshare/services/gxs/gxscircle_tests.cc \ - -# libretroshare/services/gxs/gxscircle_mintest.cc \ - - -# libretroshare/services/gxs/RsGxsNetServiceTester.cc \ +################################ Serialiser ################################ +HEADERS += libretroshare/serialiser/support.h \ + libretroshare/serialiser/rstlvutil.h \ + +SOURCES += libretroshare/serialiser/rsturtleitem_test.cc \ + libretroshare/serialiser/rsbaseitem_test.cc \ + libretroshare/serialiser/rsgxsupdateitem_test.cc \ + libretroshare/serialiser/rsmsgitem_test.cc \ + libretroshare/serialiser/rsstatusitem_test.cc \ + libretroshare/serialiser/rsnxsitems_test.cc \ + libretroshare/serialiser/rsgxsiditem_test.cc \ +# libretroshare/serialiser/rsphotoitem_test.cc \ + libretroshare/serialiser/tlvbase_test2.cc \ + libretroshare/serialiser/tlvrandom_test.cc \ + libretroshare/serialiser/tlvbase_test.cc \ + libretroshare/serialiser/tlvstack_test.cc \ + libretroshare/serialiser/tlvitems_test.cc \ +# libretroshare/serialiser/rsgrouteritem_test.cc \ + libretroshare/serialiser/tlvtypes_test.cc \ + libretroshare/serialiser/tlvkey_test.cc \ + libretroshare/serialiser/support.cc \ + libretroshare/serialiser/rstlvutil.cc \ + +# Still to convert these. +# libretroshare/serialiser/rsconfigitem_test.cc \ +# libretroshare/serialiser/rsgrouteritem_test.cc \ + + +################################## GXS ##################################### + +HEADERS += libretroshare/gxs/common/data_support.h \ + +SOURCES += libretroshare/gxs/common/data_support.cc \ + +HEADERS += libretroshare/gxs/nxs_test/nxsdummyservices.h \ + libretroshare/gxs/nxs_test/nxsgrptestscenario.h \ + libretroshare/gxs/nxs_test/nxsmsgtestscenario.h \ + libretroshare/gxs/nxs_test/nxsgrpsync_test.h \ + libretroshare/gxs/nxs_test/nxsmsgsync_test.h \ + libretroshare/gxs/nxs_test/nxstesthub.h \ + libretroshare/gxs/nxs_test/nxstestscenario.h \ + libretroshare/gxs/nxs_test/nxsgrpsyncdelayed.h + +SOURCES += libretroshare/gxs/nxs_test/nxsdummyservices.cc \ + libretroshare/gxs/nxs_test/nxsgrptestscenario.cc \ + libretroshare/gxs/nxs_test/nxsmsgtestscenario.cc \ + libretroshare/gxs/nxs_test/nxstesthub.cc \ + libretroshare/gxs/nxs_test/rsgxsnetservice_test.cc \ + libretroshare/gxs/nxs_test/nxsmsgsync_test.cc \ + libretroshare/gxs/nxs_test/nxsgrpsync_test.cc \ + libretroshare/gxs/nxs_test/nxsgrpsyncdelayed.cc + +HEADERS += libretroshare/gxs/gen_exchange/genexchangetester.h \ + libretroshare/gxs/gen_exchange/gxspublishmsgtest.h \ + libretroshare/gxs/gen_exchange/genexchangetestservice.h \ + libretroshare/gxs/gen_exchange/gxspublishgrouptest.h \ + libretroshare/gxs/gen_exchange/rsdummyservices.h \ + libretroshare/gxs/gen_exchange/gxsteststats.cpp + +# libretroshare/gxs/gen_exchange/gxsmsgrelatedtest.h \ + +SOURCES += libretroshare/gxs/gen_exchange/gxspublishgrouptest.cc \ + libretroshare/gxs/gen_exchange/gxsteststats.cpp \ + libretroshare/gxs/gen_exchange/gxspublishmsgtest.cc \ + libretroshare/gxs/gen_exchange/rsdummyservices.cc \ + libretroshare/gxs/gen_exchange/rsgenexchange_test.cc \ + libretroshare/gxs/gen_exchange/genexchangetester.cc \ + libretroshare/gxs/gen_exchange/genexchangetestservice.cc \ + +SOURCES += libretroshare/gxs/security/gxssecurity_test.cc + +# libretroshare/gxs/gen_exchange/gxsmsgrelatedtest.cc \ + +HEADERS += libretroshare/gxs/data_service/rsdataservice_test.h \ + +SOURCES += libretroshare/gxs/data_service/rsdataservice_test.cc \ + libretroshare/gxs/data_service/rsgxsdata_test.cc \ + + +################################ dbase ##################################### + + +#SOURCES += libretroshare/dbase/fisavetest.cc \ +# libretroshare/dbase/fitest2.cc \ +# libretroshare/dbase/searchtest.cc \ + +# libretroshare/dbase/ficachetest.cc \ +# libretroshare/dbase/fimontest.cc \ + + +############################### services ################################### + +SOURCES += libretroshare/services/status/status_test.cc \ + +############################### gxs ######################################## + +HEADERS += libretroshare/services/gxs/rsgxstestitems.h \ + libretroshare/services/gxs/gxstestservice.h \ + libretroshare/services/gxs/GxsIsolatedServiceTester.h \ + libretroshare/services/gxs/GxsPeerNode.h \ + libretroshare/services/gxs/GxsPairServiceTester.h \ + libretroshare/services/gxs/FakePgpAuxUtils.h \ + +# libretroshare/services/gxs/RsGxsNetServiceTester.h \ + +SOURCES += libretroshare/services/gxs/rsgxstestitems.cc \ + libretroshare/services/gxs/gxstestservice.cc \ + libretroshare/services/gxs/GxsIsolatedServiceTester.cc \ + libretroshare/services/gxs/GxsPeerNode.cc \ + libretroshare/services/gxs/GxsPairServiceTester.cc \ + libretroshare/services/gxs/FakePgpAuxUtils.cc \ + libretroshare/services/gxs/nxsbasic_test.cc \ + libretroshare/services/gxs/nxspair_tests.cc \ + libretroshare/services/gxs/gxscircle_tests.cc \ + +# libretroshare/services/gxs/gxscircle_mintest.cc \ + + +# libretroshare/services/gxs/RsGxsNetServiceTester.cc \ From f39272a709de4fb933f939f944c9a23cb09a16ba Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 3 Nov 2016 21:44:40 +0100 Subject: [PATCH 38/52] fixed compilation in debug mode for p3filelists.cc --- libretroshare/src/file_sharing/p3filelists.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index 42d906781..e3b1fa7cd 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -39,7 +39,7 @@ #define P3FILELISTS_DEBUG() std::cerr << time(NULL) << " : FILE_LISTS : " << __FUNCTION__ << " : " #define P3FILELISTS_ERROR() std::cerr << "***ERROR***" << " : FILE_LISTS : " << __FUNCTION__ << " : " -//#define DEBUG_P3FILELISTS 1 +#define DEBUG_P3FILELISTS 1 static const uint32_t P3FILELISTS_UPDATE_FLAG_NOTHING_CHANGED = 0x0000 ; static const uint32_t P3FILELISTS_UPDATE_FLAG_REMOTE_MAP_CHANGED = 0x0001 ; From 79632ed27b6a0aef4c76d0ff68aa0852a3765ebf Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 4 Nov 2016 21:48:58 +0100 Subject: [PATCH 39/52] fixed compilation on windows --- libretroshare/src/crypto/chacha20.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libretroshare/src/crypto/chacha20.cpp b/libretroshare/src/crypto/chacha20.cpp index 4561d281f..17c0eb920 100644 --- a/libretroshare/src/crypto/chacha20.cpp +++ b/libretroshare/src/crypto/chacha20.cpp @@ -37,6 +37,7 @@ #include "crypto/chacha20.h" #include "util/rsprint.h" +#include "util/rsrandom.h" #include "util/rsscopetimer.h" #define rotl(x,n) { x = (x << n) | (x >> (-n & 31)) ;} @@ -62,11 +63,11 @@ struct uint256_32 b[4]=b4; b[5]=b5; b[6]=b6; b[7]=b7; } - static uint256_32 random() // non cryptographically secure random. Just for testing. + static uint256_32 random() { uint256_32 r ; for(uint32_t i=0;i<8;++i) - r.b[i] = lrand48() & 0xffffffff ; + r.b[i] = RSRandom::random_u32(); return r; } From 2ef51edb8c84df3f766e063c289064cc82eb552d Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 4 Nov 2016 21:51:18 +0100 Subject: [PATCH 40/52] fixed wrong comment about RS_FILE_HINT_SEARCHABLE flag --- libretroshare/src/retroshare/rsfiles.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index b45aedcc7..a9b50d714 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -74,9 +74,9 @@ const FileSearchFlags RS_FILE_HINTS_DOWNLOAD ( 0x00000010 ); const FileSearchFlags RS_FILE_HINTS_UPLOAD ( 0x00000020 ); const FileSearchFlags RS_FILE_HINTS_SPEC_ONLY ( 0x01000000 ); -const FileSearchFlags RS_FILE_HINTS_NETWORK_WIDE ( 0x00000080 );// anonymously shared over network +const FileSearchFlags RS_FILE_HINTS_NETWORK_WIDE ( 0x00000080 );// can be downloaded anonymously const FileSearchFlags RS_FILE_HINTS_BROWSABLE ( 0x00000100 );// browsable by friends -const FileSearchFlags RS_FILE_HINTS_SEARCHABLE ( 0x00000200 );// browsable by friends +const FileSearchFlags RS_FILE_HINTS_SEARCHABLE ( 0x00000200 );// can be searched anonymously const FileSearchFlags RS_FILE_HINTS_PERMISSION_MASK ( 0x00000380 );// OR of the last tree flags. Used to filter out. // Flags used when requesting a transfer From ffcf44b3fed8523076966497e2b2701764a56942 Mon Sep 17 00:00:00 2001 From: csoler Date: Fri, 4 Nov 2016 21:54:28 +0100 Subject: [PATCH 41/52] removing call to drand48(). RSRandom is safer --- libretroshare/src/crypto/chacha20.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libretroshare/src/crypto/chacha20.cpp b/libretroshare/src/crypto/chacha20.cpp index 17c0eb920..bee4f034e 100644 --- a/libretroshare/src/crypto/chacha20.cpp +++ b/libretroshare/src/crypto/chacha20.cpp @@ -791,11 +791,11 @@ bool perform_tests() uint256_32 n1 = uint256_32::random(); uint256_32 p1 = uint256_32::random(); - if(drand48() < 0.2) + if(RSRandom::random_f32() < 0.2) { p1.b[7] = 0 ; - if(drand48() < 0.1) + if(RSRandom::random_f32() < 0.1) p1.b[6] = 0 ; } From 192cbe1edae177ab7f80441dadd211ab25bd6df4 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 5 Nov 2016 14:57:39 +0100 Subject: [PATCH 42/52] Create two #define in pqistreamer.cc to easily disable packet slicing and/or grouping --- libretroshare/src/pqi/pqistreamer.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libretroshare/src/pqi/pqistreamer.cc b/libretroshare/src/pqi/pqistreamer.cc index a96c93148..f5ef365af 100644 --- a/libretroshare/src/pqi/pqistreamer.cc +++ b/libretroshare/src/pqi/pqistreamer.cc @@ -64,6 +64,10 @@ static const int PQISTREAM_PACKET_SLICING_PROBE_DELAY = 60; // send every 6 static uint8_t PACKET_SLICING_PROBE_BYTES[8] = { 0x02, 0xaa, 0xbb, 0xcc, 0x00, 0x00, 0x00, 0x08 } ; +/* Change to true to disable packet slicing and/or packet grouping, if needed */ +#define DISABLE_PACKET_SLICING false +#define DISABLE_PACKET_GROUPING false + /* This removes the print statements (which hammer pqidebug) */ /*** #define RSITEM_DEBUG 1 @@ -629,7 +633,7 @@ int pqistreamer::handleoutgoing_locked() ++k ; } } - while(mPkt_wpending_size < (uint32_t)maxbytes && mPkt_wpending_size < PQISTREAM_OPTIMAL_PACKET_SIZE ) ; + while(mPkt_wpending_size < (uint32_t)maxbytes && mPkt_wpending_size < PQISTREAM_OPTIMAL_PACKET_SIZE && !DISABLE_PACKET_GROUPING) ; #ifdef DEBUG_PQISTREAMER if(k > 1) @@ -787,7 +791,7 @@ start_packet_read: if(!memcmp(block,PACKET_SLICING_PROBE_BYTES,8)) { - mAcceptsPacketSlicing = true ; + mAcceptsPacketSlicing = (true && !DISABLE_PACKET_SLICING); #ifdef DEBUG_PACKET_SLICING std::cerr << "(II) Enabling packet slicing!" << std::endl; #endif @@ -815,7 +819,7 @@ continue_packet: #endif is_partial_packet = true ; - mAcceptsPacketSlicing = true ; // this is needed + mAcceptsPacketSlicing = (true && !DISABLE_PACKET_SLICING); // this is needed } else extralen = getRsItemSize(block) - blen; // old style packet type From 1e919a141c97230350c9be7bbe842829ba09260c Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 5 Nov 2016 15:30:07 +0100 Subject: [PATCH 43/52] set delay between directory sweep to 60 secs and a-synced sweeps for different friends. Set drop time to 600 for un-answered dir sync requests --- libretroshare/src/file_sharing/directory_storage.cc | 4 +++- libretroshare/src/file_sharing/directory_storage.h | 7 +++++++ libretroshare/src/file_sharing/file_sharing_defaults.h | 8 +++++++- libretroshare/src/file_sharing/p3filelists.cc | 9 ++------- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/libretroshare/src/file_sharing/directory_storage.cc b/libretroshare/src/file_sharing/directory_storage.cc index 950e37e30..e2d47b5f5 100644 --- a/libretroshare/src/file_sharing/directory_storage.cc +++ b/libretroshare/src/file_sharing/directory_storage.cc @@ -756,7 +756,9 @@ RemoteDirectoryStorage::RemoteDirectoryStorage(const RsPeerId& pid,const std::st { load(fname) ; - std::cerr << "Loaded remote directory for peer " << pid << std::endl; + mLastSweepTime = time(NULL) - (RSRandom::random_u32() % DELAY_BETWEEN_REMOTE_DIRECTORIES_SWEEP) ; + + std::cerr << "Loaded remote directory for peer " << pid << ", inited last sweep time to " << time(NULL) - mLastSweepTime << " secs ago." << std::endl; #ifdef DEBUG_REMOTE_DIRECTORY_STORAGE mFileHierarchy->print(); #endif diff --git a/libretroshare/src/file_sharing/directory_storage.h b/libretroshare/src/file_sharing/directory_storage.h index 4d4e5df97..22282e6d3 100644 --- a/libretroshare/src/file_sharing/directory_storage.h +++ b/libretroshare/src/file_sharing/directory_storage.h @@ -194,8 +194,15 @@ public: */ void checkSave() ; + /*! + * \brief lastSweepTime + * returns the last time a sweep has been done over the directory in order to check update TS. + * \return + */ + time_t& lastSweepTime() { return mLastSweepTime ; } private: time_t mLastSavedTime ; + time_t mLastSweepTime ; bool mChanged ; std::string mFileName; }; diff --git a/libretroshare/src/file_sharing/file_sharing_defaults.h b/libretroshare/src/file_sharing/file_sharing_defaults.h index 520fc61ea..b2b64afc9 100644 --- a/libretroshare/src/file_sharing/file_sharing_defaults.h +++ b/libretroshare/src/file_sharing/file_sharing_defaults.h @@ -28,7 +28,8 @@ static const uint32_t DELAY_BETWEEN_DIRECTORY_UPDATES = 600 ; // 10 minutes static const uint32_t DELAY_BETWEEN_REMOTE_DIRECTORY_SYNC_REQ = 120 ; // 2 minutes -static const uint32_t DELAY_BETWEEN_LOCAL_DIRECTORIES_TS_UPDATE = 20 ; // 20 sec. Buy we only update for real if something has changed. +static const uint32_t DELAY_BETWEEN_LOCAL_DIRECTORIES_TS_UPDATE = 20 ; // 20 sec. But we only update for real if something has changed. +static const uint32_t DELAY_BETWEEN_REMOTE_DIRECTORIES_SWEEP = 60 ; // 60 sec. static const std::string HASH_CACHE_DURATION_SS = "HASH_CACHE_DURATION" ; // key string to store hash remembering time static const std::string WATCH_FILE_DURATION_SS = "WATCH_FILES_DELAY" ; // key to store delay before re-checking for new files @@ -43,3 +44,8 @@ static const uint32_t MIN_INTERVAL_BETWEEN_REMOTE_DIRECTORY_SAVE = 23 ; // static const uint32_t MAX_DIR_SYNC_RESPONSE_DATA_SIZE = 20000 ; // Maximum RsItem data size in bytes for serialised directory transmission static const uint32_t DEFAULT_HASH_STORAGE_DURATION_DAYS = 30 ; // remember deleted/inaccessible files for 30 days + +static const uint32_t NB_FRIEND_INDEX_BITS = 10 ; // Do not change this! +static const uint32_t NB_ENTRY_INDEX_BITS = 22 ; // Do not change this! +static const uint32_t ENTRY_INDEX_BIT_MASK = 0x003fffff ; // used for storing (EntryIndex,Friend) couples into a 32bits pointer. Depends on the two values just before. Dont change! +static const uint32_t DELAY_BEFORE_DROP_REQUEST = 600; // every 10 min diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index e3b1fa7cd..e7acc62e8 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -46,11 +46,6 @@ static const uint32_t P3FILELISTS_UPDATE_FLAG_REMOTE_MAP_CHANGED = 0x0001 ; static const uint32_t P3FILELISTS_UPDATE_FLAG_LOCAL_DIRS_CHANGED = 0x0002 ; static const uint32_t P3FILELISTS_UPDATE_FLAG_REMOTE_DIRS_CHANGED = 0x0004 ; -static const uint32_t NB_FRIEND_INDEX_BITS = 10 ; -static const uint32_t NB_ENTRY_INDEX_BITS = 22 ; -static const uint32_t ENTRY_INDEX_BIT_MASK = 0x003fffff ; // used for storing (EntryIndex,Friend) couples into a 32bits pointer. -static const uint32_t DELAY_BEFORE_DROP_REQUEST = 55 ; // every 55 secs, for debugging. Should be evey 10 minutes or so. - p3FileDatabase::p3FileDatabase(p3ServiceControl *mpeers) : mServCtrl(mpeers), mFLSMtx("p3FileLists") { @@ -209,7 +204,7 @@ int p3FileDatabase::tick() for(uint32_t i=0;ipeerId()) != online_peers.end()) + if(online_peers.find(mRemoteDirectories[i]->peerId()) != online_peers.end() && mRemoteDirectories[i]->lastSweepTime() + DELAY_BETWEEN_REMOTE_DIRECTORIES_SWEEP < now) { #ifdef DEBUG_FILE_HIERARCHY P3FILELISTS_DEBUG() << "Launching recurs sweep of friend directory " << mRemoteDirectories[i]->peerId() << ". Content currently is:" << std::endl; @@ -217,6 +212,7 @@ int p3FileDatabase::tick() #endif locked_recursSweepRemoteDirectory(mRemoteDirectories[i],mRemoteDirectories[i]->root(),0) ; + mRemoteDirectories[i]->lastSweepTime() = now ; } mRemoteDirectories[i]->checkSave() ; @@ -497,7 +493,6 @@ void p3FileDatabase::cleanup() #ifdef DEBUG_P3FILELISTS P3FILELISTS_DEBUG() << " removing pending request " << std::hex << it->first << std::dec << " for peer " << it->second.peer_id << ", because peer is offline or request is too old." << std::endl; #endif - std::map::iterator tmp(it); ++tmp; mPendingSyncRequests.erase(it) ; From a97fa1e2cb07a39f89452ca83a912ba44945eb0c Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 5 Nov 2016 16:07:30 +0100 Subject: [PATCH 44/52] fixed generation of pseudo-random request ids in p3filelists --- libretroshare/src/file_sharing/p3filelists.cc | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/libretroshare/src/file_sharing/p3filelists.cc b/libretroshare/src/file_sharing/p3filelists.cc index e7acc62e8..3bbf5fb9a 100644 --- a/libretroshare/src/file_sharing/p3filelists.cc +++ b/libretroshare/src/file_sharing/p3filelists.cc @@ -39,7 +39,7 @@ #define P3FILELISTS_DEBUG() std::cerr << time(NULL) << " : FILE_LISTS : " << __FUNCTION__ << " : " #define P3FILELISTS_ERROR() std::cerr << "***ERROR***" << " : FILE_LISTS : " << __FUNCTION__ << " : " -#define DEBUG_P3FILELISTS 1 +//#define DEBUG_P3FILELISTS 1 static const uint32_t P3FILELISTS_UPDATE_FLAG_NOTHING_CHANGED = 0x0000 ; static const uint32_t P3FILELISTS_UPDATE_FLAG_REMOTE_MAP_CHANGED = 0x0001 ; @@ -1454,25 +1454,23 @@ void p3FileDatabase::locked_recursSweepRemoteDirectory(RemoteDirectoryStorage *r p3FileDatabase::DirSyncRequestId p3FileDatabase::makeDirSyncReqId(const RsPeerId& peer_id,const RsFileHash& hash) { static uint64_t random_bias = RSRandom::random_u64(); - uint64_t r = 0 ; + + uint8_t mem[RsPeerId::SIZE_IN_BYTES + RsFileHash::SIZE_IN_BYTES]; + memcpy(mem,peer_id.toByteArray(),RsPeerId::SIZE_IN_BYTES) ; + memcpy(&mem[RsPeerId::SIZE_IN_BYTES],hash.toByteArray(),RsFileHash::SIZE_IN_BYTES) ; + + RsFileHash tmp = RsDirUtil::sha1sum(mem,RsPeerId::SIZE_IN_BYTES + RsFileHash::SIZE_IN_BYTES) ; // This is kind of arbitrary. The important thing is that the same ID needs to be generated every time for a given (peer_id,entry index) pair, in a way // that cannot be brute-forced or reverse-engineered, which explains the random bias and the usage of the hash, that is itself random. - for(uint32_t i=0;iflags; #ifdef DEBUG_P3FILELISTS - P3FILELISTS_DEBUG() << " Pushing req in pending list with peer id " << data.peer_id << std::endl; + P3FILELISTS_DEBUG() << " Pushing req " << std::hex << sync_req_id << std::dec << " in pending list with peer id " << data.peer_id << std::endl; #endif mPendingSyncRequests[sync_req_id] = data ; From 390bdfe12f1771fe0459cf7379aa5946150134fe Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 5 Nov 2016 17:03:31 +0100 Subject: [PATCH 45/52] added request for sync on double click item for shared file lists --- retroshare-gui/src/gui/SharedFilesDialog.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/retroshare-gui/src/gui/SharedFilesDialog.cpp b/retroshare-gui/src/gui/SharedFilesDialog.cpp index e0b37e3d2..13094f87a 100644 --- a/retroshare-gui/src/gui/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/SharedFilesDialog.cpp @@ -266,6 +266,7 @@ RemoteSharedFilesDialog::RemoteSharedFilesDialog(QWidget *parent) connect(ui.downloadButton, SIGNAL(clicked()), this, SLOT(downloadRemoteSelected())); connect(ui.dirTreeView, SIGNAL( expanded(const QModelIndex & ) ), this, SLOT( expanded(const QModelIndex & ) ) ); + connect(ui.dirTreeView, SIGNAL( doubleClicked(const QModelIndex & ) ), this, SLOT( expanded(const QModelIndex & ) ) ); // load settings processSettings(true); From e4e366766f9577243790634bc80e7e5b37a5d8bb Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 5 Nov 2016 17:32:40 +0100 Subject: [PATCH 46/52] fixed bug that caused hierarchies that contain files being hashed to not send updates when the hash is finished --- libretroshare/src/file_sharing/dir_hierarchy.cc | 11 ++++++++--- libretroshare/src/file_sharing/dir_hierarchy.h | 2 +- libretroshare/src/file_sharing/directory_storage.cc | 6 ++++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/libretroshare/src/file_sharing/dir_hierarchy.cc b/libretroshare/src/file_sharing/dir_hierarchy.cc index eaeb1201a..19d0b543a 100644 --- a/libretroshare/src/file_sharing/dir_hierarchy.cc +++ b/libretroshare/src/file_sharing/dir_hierarchy.cc @@ -594,12 +594,12 @@ bool InternalFileHierarchyStorage::setTS(const DirectoryStorage::EntryIndex& ind // Do a complete recursive sweep over sub-directories and files, and update the lst modf TS. This could be also performed by a cleanup method. -time_t InternalFileHierarchyStorage::recursUpdateLastModfTime(const DirectoryStorage::EntryIndex& dir_index) +time_t InternalFileHierarchyStorage::recursUpdateLastModfTime(const DirectoryStorage::EntryIndex& dir_index,bool& unfinished_files_present) { DirEntry& d(*static_cast(mNodes[dir_index])) ; time_t largest_modf_time = d.dir_modtime ; - bool unfinished_files_present = false ; + unfinished_files_present = false ; for(uint32_t i=0;irecursUpdateLastModfTime(EntryIndex(0)) ; + bool unfinished_files_below ; + + time_t last_modf_time = mFileHierarchy->recursUpdateLastModfTime(EntryIndex(0),unfinished_files_below) ; mTSChanged = false ; #ifdef DEBUG_LOCAL_DIRECTORY_STORAGE - std::cerr << "LocalDirectoryStorage: global last modf time is " << last_modf_time << " (which is " << time(NULL) - last_modf_time << " secs ago)" << std::endl; + std::cerr << "LocalDirectoryStorage: global last modf time is " << last_modf_time << " (which is " << time(NULL) - last_modf_time << " secs ago), unfinished files below=" << unfinished_files_below << std::endl; #else // remove unused variable warning // variable is only used for debugging From 78d6735b52f7ec82aaa0e3b7bec8ed2e728e0707 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 5 Nov 2016 19:58:06 +0100 Subject: [PATCH 47/52] Create 2 #define in pqistreamer to easily disable packet slicing/grouping --- libretroshare/src/pqi/pqistreamer.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libretroshare/src/pqi/pqistreamer.cc b/libretroshare/src/pqi/pqistreamer.cc index f5ef365af..aa52ec02c 100644 --- a/libretroshare/src/pqi/pqistreamer.cc +++ b/libretroshare/src/pqi/pqistreamer.cc @@ -791,7 +791,7 @@ start_packet_read: if(!memcmp(block,PACKET_SLICING_PROBE_BYTES,8)) { - mAcceptsPacketSlicing = (true && !DISABLE_PACKET_SLICING); + mAcceptsPacketSlicing = !DISABLE_PACKET_SLICING; #ifdef DEBUG_PACKET_SLICING std::cerr << "(II) Enabling packet slicing!" << std::endl; #endif @@ -819,7 +819,7 @@ continue_packet: #endif is_partial_packet = true ; - mAcceptsPacketSlicing = (true && !DISABLE_PACKET_SLICING); // this is needed + mAcceptsPacketSlicing = !DISABLE_PACKET_SLICING; // this is needed } else extralen = getRsItemSize(block) - blen; // old style packet type From 8cebb33dedd336265f72a2d1526916986d2bc7bb Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 5 Nov 2016 20:59:41 +0100 Subject: [PATCH 48/52] updated ubuntu changelog --- build_scripts/Debian+Ubuntu/changelog | 90 +++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/build_scripts/Debian+Ubuntu/changelog b/build_scripts/Debian+Ubuntu/changelog index 666e580fb..cbfde1047 100644 --- a/build_scripts/Debian+Ubuntu/changelog +++ b/build_scripts/Debian+Ubuntu/changelog @@ -1,5 +1,95 @@ retroshare06 (0.6.1-1.XXXXXX~YYYYYY) YYYYYY; urgency=low + e4e3667 csoler Sat, 5 Nov 2016 17:32:40 +0100 fixed bug that caused hierarchies that contain files being hashed to not send updates when the hash is finished + 390bdfe csoler Sat, 5 Nov 2016 17:03:31 +0100 added request for sync on double click item for shared file lists + a97fa1e csoler Sat, 5 Nov 2016 16:07:30 +0100 fixed generation of pseudo-random request ids in p3filelists + 1e919a1 csoler Sat, 5 Nov 2016 15:30:07 +0100 set delay between directory sweep to 60 secs and a-synced sweeps for different friends. Set drop time to 600 for un-answered dir sync requests + ffcf44b csoler Fri, 4 Nov 2016 21:54:28 +0100 removing call to drand48(). RSRandom is safer + 2ef51ed csoler Fri, 4 Nov 2016 21:51:18 +0100 fixed wrong comment about RS_FILE_HINT_SEARCHABLE flag + 79632ed csoler Fri, 4 Nov 2016 21:48:58 +0100 fixed compilation on windows + f39272a csoler Thu, 3 Nov 2016 21:44:40 +0100 fixed compilation in debug mode for p3filelists.cc + 8c1a653 csoler Fri, 4 Nov 2016 20:02:14 +0100 Merge pull request #557 from mr-alice/v0.6-FTEncryption + 2bb9a87 mr-alice Fri, 4 Nov 2016 13:52:11 +0100 merged and fixed conflict with upstream/master + 30860b8 mr-alice Fri, 4 Nov 2016 13:46:20 +0100 removed ^M that polluted unittests.pro + 45cb442 csoler Fri, 4 Nov 2016 09:47:49 +0100 Merge pull request #558 from csoler/v0.6-FileListsOptim + 2bf2465 csoler Fri, 4 Nov 2016 09:18:34 +0100 Merge pull request #498 from PhenomRetroShare/Fix_ElCapitanCompil + 8dacb22 csoler Thu, 3 Nov 2016 22:32:27 +0100 reducing linear cost of allocateNewIndex to constant. Should improve huge lags when receiving big file lists for the first time + e324d7d mr-alice Thu, 3 Nov 2016 20:31:47 +0100 removed warning in ftserver for rejected non encrypted tunnels + 8653649 mr-alice Thu, 3 Nov 2016 20:26:35 +0100 fixed two bugs in ShareManager popup menu + 29b5bfe mr-alice Thu, 3 Nov 2016 08:50:13 +0100 attempt to fixed leading tabs + 2db8dbd Phenom Sat, 16 Jul 2016 23:10:00 +0200 Fix El Capitan OSX 10.11 Compil + 1c2cfb2 mr-alice Wed, 2 Nov 2016 21:32:14 +0100 removed debug info in ftServer + 5aef67d mr-alice Wed, 2 Nov 2016 21:31:14 +0100 fixed tooltips in ShareManager, and fixed anonymous search mechanism + d2118c5 mr-alice Wed, 2 Nov 2016 20:51:42 +0100 supressed deadlock in ftController due to calling ftServer from ftcontroller itself + 46dd5be csoler Tue, 1 Nov 2016 16:30:46 +0100 Merge pull request #554 from hunbernd/feature/paste-RS-link + 02f442a mr-alice Tue, 1 Nov 2016 14:28:00 +0100 changed naming for files visibility + 8c7c764 mr-alice Tue, 1 Nov 2016 14:23:13 +0100 fixed conflicts in merging upstream/master to v0.6-FTEncryption + 6a3610e mr-alice Tue, 1 Nov 2016 14:13:43 +0100 disallow double tunnels (encrypted+clear) in Accepted mode, since it is not needed + ffdac64 mr-alice Tue, 1 Nov 2016 11:57:25 +0100 fixed swarming with encrypted end-to-end tunnels + c6df59a mr-alice Tue, 1 Nov 2016 11:11:28 +0100 fixed bug in duplication of virtual dir names + 761d595 mr-alice Tue, 1 Nov 2016 10:46:29 +0100 fixed layout and names in ShareManager and SharedFilesDialog + 3430eec mr-alice Tue, 1 Nov 2016 10:30:36 +0100 fixed display of share flags as a proper nice icon set + 8fe85b9 mr-alice Mon, 31 Oct 2016 23:24:35 +0100 improved ShareManager a little bit more + 9d586bc mr-alice Mon, 31 Oct 2016 16:28:26 +0100 made a drastic simplification pass on the ShareManager, which now only needs a single window except for selecting files using a QFileDialog + e8e054e mr-alice Mon, 31 Oct 2016 14:26:01 +0100 addednew flag for anonymous search. Merged the two browsable flags in one single flag. + f934e88 csoler Mon, 31 Oct 2016 12:12:40 +0100 Merge pull request #555 from hunbernd/fix/random-emoji-order + 36dc532 hunbernd Mon, 31 Oct 2016 00:23:39 +0100 Automatically detect retroshare links when pasting text + 05b5c08 hunbernd Sat, 10 Sep 2016 21:59:45 +0200 Fixed emoticon order + 5b9ef04 mr-alice Sun, 30 Oct 2016 15:33:05 +0100 improved debug output in ftserver + def20a3 mr-alice Sun, 30 Oct 2016 15:11:22 +0100 encrypted FT works. Fixed last bugs in ftServer + 34dcb41 mr-alice Sun, 30 Oct 2016 11:36:00 +0100 fixed a few bugs in ftServer for encrypted tunnel management + 9a88161 mr-alice Sat, 29 Oct 2016 18:35:48 +0200 added record for H(H(F)) in LocalDirectoryStorage + d843c1c mr-alice Sat, 29 Oct 2016 18:18:02 +0200 put consts behind serial_size() and serialise() in turtle items and ft items + babc126 mr-alice Sat, 29 Oct 2016 17:59:03 +0200 added default encryption policy variable and GUI to change it + 8486346 mr-alice Wed, 26 Oct 2016 22:05:56 +0200 added new encryption/authentication format AEAD_chacha20_sha256 + c87ca67 mr-alice Wed, 26 Oct 2016 18:15:47 +0200 improved efficiency of AEAD + 88298b9 mr-alice Wed, 26 Oct 2016 14:45:21 +0200 added check for cleartext in AEAD test vector #1 + 42f6f26 mr-alice Wed, 26 Oct 2016 14:36:35 +0200 fixed bug in AEAD + 7e536ef csoler Wed, 26 Oct 2016 11:35:30 +0200 Merge pull request #549 from PhenomRetroShare/Fix_PR#536 + 177752e mr-alice Tue, 25 Oct 2016 23:16:36 +0200 fixed a few bugs in AEAD construction based on test results + 32e54e5 Phenom Tue, 25 Oct 2016 14:58:06 +0200 Fix PR#536 revealing of bad factor management in StyledElidedLabel. + 0570427 mr-alice Tue, 25 Oct 2016 14:09:39 +0200 added google test for chacha20 code + 0387a28 mr-alice Tue, 25 Oct 2016 00:08:27 +0200 added methods to get files from hash(hash) in directory_storage and ftServer + 5f5b0d4 csoler Mon, 24 Oct 2016 20:16:21 +0200 Merge pull request #548 from PhenomRetroShare/Fix_PR#540 + fd5a5cc Phenom Mon, 24 Oct 2016 20:11:47 +0200 Fix PR#540 + 2d72b88 mr-alice Mon, 24 Oct 2016 15:59:34 +0200 added code for AEAD construction + bd4c252 csoler Sun, 23 Oct 2016 23:30:56 +0200 Merge pull request #539 from RetroShare/md-fix + f3bebc0 csoler Sun, 23 Oct 2016 23:29:06 +0200 Merge pull request #540 from PhenomRetroShare/Fix_EmbedInHtmlAhref + c77d052 csoler Sun, 23 Oct 2016 23:25:53 +0200 Merge pull request #536 from PhenomRetroShare/Add_ElidedLabelToGroupTreeWidget + 04992c9 csoler Sun, 23 Oct 2016 23:15:32 +0200 Merge pull request #543 from PhenomRetroShare/Add_TooltipOnComments + e525461 csoler Sun, 23 Oct 2016 23:14:29 +0200 Merge pull request #542 from PhenomRetroShare/Add_PasteRsLinkInTextFields + 07564c7 csoler Sun, 23 Oct 2016 23:12:22 +0200 Merge pull request #541 from PhenomRetroShare/Fix_RsLinkCopyToClipBoard + 5ccdc28 csoler Sun, 23 Oct 2016 22:51:32 +0200 Merge pull request #547 from hunbernd/fix/upload + 54ba617 hunbernd Sun, 23 Oct 2016 20:42:59 +0200 Fix: unable to upload files on Windows Caused by multiple unneeded / character in file path. + 46cf25d Phenom Sat, 22 Oct 2016 15:17:49 +0200 Fix Copy RsLink in Clipboard. + a67cf92 Phenom Sat, 22 Oct 2016 16:15:29 +0200 Add Tooltip on comments column to see too long text. + 9eafdd3 Phenom Sat, 22 Oct 2016 16:02:38 +0200 Add ability to past RsLink in some more text fields. + 58a4d39 Phenom Sat, 22 Oct 2016 14:48:23 +0200 Fix handle of url in EmbedInHtmlAhref. + f20ee21 cave Fri, 21 Oct 2016 19:56:02 +0200 Update README.md + 9d32406 mr-alice Wed, 19 Oct 2016 22:49:51 +0200 added ft decryption routine + 3ad0a81 mr-alice Wed, 19 Oct 2016 21:30:37 +0200 added encryption routine for FT + b8b78dd csoler Wed, 19 Oct 2016 15:50:22 +0200 Merge pull request #538 from Hopetech/master + ecaea05 hopetech Wed, 19 Oct 2016 15:41:25 +0200 Fix some compilation warnings + 8483c0d Phenom Sun, 16 Oct 2016 15:48:50 +0200 Add ElidedLabel to GroupTreeWidget + 997154f mr-alice Thu, 13 Oct 2016 15:13:56 +0200 added preliminary implementation of chacha20/poly1305 + 0e1fad0 csoler Thu, 13 Oct 2016 13:48:32 +0200 Merge pull request #533 from PhenomRetroShare/Fix_MissingDesktopFileShow + 4db6d6b Phenom Thu, 13 Oct 2016 13:26:44 +0200 Fix the "Desktop file is missing" shown in option page. + 64129a7 csoler Thu, 13 Oct 2016 10:05:14 +0200 Merge pull request #532 from G10h4ck/less_warning + 8de0548 Gio Thu, 13 Oct 2016 00:09:53 +0200 Merge branch 'master' into less_warning + 633a6cf Gio Wed, 12 Oct 2016 20:43:38 +0200 Fixed a bunch of warnings in safe ways + 10c269e csoler Wed, 12 Oct 2016 23:31:32 +0200 removed warning when friend directory list cannot be found + bd9a464 csoler Wed, 12 Oct 2016 23:20:38 +0200 added deterministic but unredictable hash generation for dir hashes, which should be preserved accross reboots. Should fix the msg from friends sending requests for the "wrong" dir hashes. + 3c5e12a csoler Mon, 10 Oct 2016 11:29:03 +0200 fixed compilation on windows + 4e48005 csoler Sun, 9 Oct 2016 21:43:00 +0200 replaced explicit old code in cleanupDirectory() by new code based on FolderIterator + 957d48b csoler Sun, 9 Oct 2016 21:03:01 +0200 removed folderIterator::d_name() because it duplicates file_name() + 32816ed csoler Sun, 9 Oct 2016 18:23:25 +0200 Merge pull request #531 from PhenomRetroShare/Fix_AvatarOnEditCircle + 6e8e5d0 csoler Sun, 9 Oct 2016 18:20:00 +0200 Merge pull request #529 from cavebeat/rus_patch + 3d9fb60 Phenom Sun, 9 Oct 2016 12:37:09 +0200 Fix Missing ID-Avatars in Create Circle Menu + + -- Cyril Soler Sat, 5 Nov 2016 21:00:00 +0100 + +retroshare06 (0.6.1-1.20161008.9e1f21b9~xenial) xenial; urgency=low + 9a3eb1c csoler Sat, 8 Oct 2016 14:30:58 +0200 Merge pull request #528 from sehraf/pr-drop-ssh-protobuf c55fb0d csoler Sat, 8 Oct 2016 14:11:43 +0200 Merge pull request #524 from cavebeat/compile 97f2589 csoler Sat, 8 Oct 2016 14:09:34 +0200 Merge pull request #513 from grennvyper/patch-1 From c1b1e2592089143c004cc828f4eb62cb71379d11 Mon Sep 17 00:00:00 2001 From: csoler Date: Sun, 6 Nov 2016 12:32:36 +0100 Subject: [PATCH 49/52] updated ubuntu changelog and added control file for ubuntu 16.10 --- build_scripts/Debian+Ubuntu/changelog | 2 +- build_scripts/Debian+Ubuntu/control.yakkety | 44 +++++++++++++++++++ .../Debian+Ubuntu/makeSourcePackage.sh | 2 + 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 build_scripts/Debian+Ubuntu/control.yakkety diff --git a/build_scripts/Debian+Ubuntu/changelog b/build_scripts/Debian+Ubuntu/changelog index cbfde1047..e0da54d01 100644 --- a/build_scripts/Debian+Ubuntu/changelog +++ b/build_scripts/Debian+Ubuntu/changelog @@ -86,7 +86,7 @@ retroshare06 (0.6.1-1.XXXXXX~YYYYYY) YYYYYY; urgency=low 6e8e5d0 csoler Sun, 9 Oct 2016 18:20:00 +0200 Merge pull request #529 from cavebeat/rus_patch 3d9fb60 Phenom Sun, 9 Oct 2016 12:37:09 +0200 Fix Missing ID-Avatars in Create Circle Menu - -- Cyril Soler Sat, 5 Nov 2016 21:00:00 +0100 + -- Cyril Soler Sat, 5 Nov 2016 21:00:00 +0100 retroshare06 (0.6.1-1.20161008.9e1f21b9~xenial) xenial; urgency=low diff --git a/build_scripts/Debian+Ubuntu/control.yakkety b/build_scripts/Debian+Ubuntu/control.yakkety new file mode 100644 index 000000000..9b557e3b8 --- /dev/null +++ b/build_scripts/Debian+Ubuntu/control.yakkety @@ -0,0 +1,44 @@ +Source: retroshare06 +Section: devel +Priority: standard +Maintainer: Cyril Soler +Build-Depends: debhelper (>= 7), libglib2.0-dev, libupnp-dev, libssl-dev, libxss-dev, libgnome-keyring-dev, libbz2-dev, libspeex-dev, libspeexdsp-dev, libxslt1-dev, cmake, libcurl4-openssl-dev, libopencv-dev, tcl8.6, libsqlcipher-dev, libmicrohttpd-dev, libavcodec-dev, qtmultimedia5-dev, qttools5-dev, libqt5x11extras5-dev, qt5-default +Standards-Version: 3.9.6 +Homepage: http://retroshare.sourceforge.net + +Package: retroshare06-voip-plugin +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, retroshare06, libspeex1, libspeexdsp1, libqt5multimedia5 +Description: RetroShare VOIP plugin + This package provides a plugin for RetroShare, a secured Friend-to-Friend communication + plateform. The plugin adds voice-over-IP functionality to the private chat window. Both + friends chatting together need the plugin installed to be able to talk together. + +Package: retroshare06-feedreader-plugin +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, retroshare06 +Description: RetroShare FeedReader plugin + This package provides a plugin for RetroShare, a secured Friend-to-Friend communication + plateform. The plugin adds a RSS feed reader tab to retroshare. + +Package: retroshare06-nogui +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, gnome-keyring +Conflicts: retroshare06 +Description: Secure communication with friends + This is the command-line client for RetroShare network. This client + can be contacted and talked-to using SSL. Clients exist for portable + devices running e.g. Android. + +Package: retroshare06 +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, gnome-keyring +Conflicts: retroshare06-nogui +Description: Secure communication with friends + RetroShare is a Open Source cross-platform, private and secure decentralised + commmunication platform. It lets you to securely chat and share files with your + friends and family, using a web-of-trust to authenticate peers and OpenSSL to + encrypt all communication. RetroShare provides filesharing, chat, messages, + forums and channels. + + diff --git a/build_scripts/Debian+Ubuntu/makeSourcePackage.sh b/build_scripts/Debian+Ubuntu/makeSourcePackage.sh index bd2cd2ba5..baef9cbf7 100755 --- a/build_scripts/Debian+Ubuntu/makeSourcePackage.sh +++ b/build_scripts/Debian+Ubuntu/makeSourcePackage.sh @@ -135,6 +135,8 @@ for i in ${dist}; do cp ../control.precise debian/control elif test "${i}" = "xenial" ; then cp ../control.xenial debian/control + elif test "${i}" = "yakkety" ; then + cp ../control.yakkety debian/control elif test "${i}" = "stretch" ; then cp ../control.${i} debian/control elif test "${i}" = "jessie" ; then From 7a58a87859de8651fd849e5d746882fe21fe1275 Mon Sep 17 00:00:00 2001 From: Phenom Date: Sun, 4 Sep 2016 13:08:09 +0200 Subject: [PATCH 50/52] Add MacOS compilation test on Travis CI --- .travis.yml | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 80b719c06..bae0f21c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,36 @@ -sudo: required -dist: trusty language: cpp -compiler: - - gcc +matrix: + include: + - os: linux + dist: trusty + sudo: required + compiler: gcc + - os: osx + osx_image: xcode6.2 + compiler: clang + sudo: false before_install: - - sudo apt-get update - - sudo apt-get install -y build-essential checkinstall cmake libavutil-dev libavcodec-dev libavformat-dev libbz2-dev libcurl4-openssl-dev libcv-dev libopencv-highgui-dev libhighgui-dev libgnome-keyring-dev libgstreamer-plugins-base0.10-dev libgstreamer0.10-dev libjasper-dev libjpeg-dev libmicrohttpd-dev libopencv-dev libprotobuf-dev libqt4-dev libspeex-dev libspeexdsp-dev libsqlite3-dev libssl-dev libswscale-dev libtbb-dev libtiff4-dev libupnp-dev libv4l-dev libxine-dev libxslt1-dev libxss-dev pkg-config protobuf-compiler python-dev qtmobility-dev + - if [ $TRAVIS_OS_NAME == linux ]; then sudo apt-get update; fi + - if [ $TRAVIS_OS_NAME == linux ]; then sudo apt-get install -y build-essential checkinstall cmake libavutil-dev libavcodec-dev libavformat-dev libbz2-dev libcurl4-openssl-dev libcv-dev libopencv-highgui-dev libhighgui-dev libgnome-keyring-dev libgstreamer-plugins-base0.10-dev libgstreamer0.10-dev libjasper-dev libjpeg-dev libmicrohttpd-dev libopencv-dev libprotobuf-dev libqt4-dev libspeex-dev libspeexdsp-dev libsqlite3-dev libssl-dev libswscale-dev libtbb-dev libtiff4-dev libupnp-dev libv4l-dev libxine-dev libxslt1-dev libxss-dev pkg-config protobuf-compiler python-dev qtmobility-dev; fi + + +# - if [ $TRAVIS_OS_NAME == osx ]; then xcode-select --install ; fi + - if [ $TRAVIS_OS_NAME == osx ]; then brew update ; fi +# - if [ $TRAVIS_OS_NAME == osx ]; then brew install qt55 openssl miniupnpc libmicrohttpd speex homebrew/science/opencv ffmpeg sqlcipher ; fi + - if [ $TRAVIS_OS_NAME == osx ]; then brew install qt55 openssl miniupnpc libmicrohttpd speex ffmpeg sqlcipher ; fi + - if [ $TRAVIS_OS_NAME == osx ]; then brew link --force qt55 ; fi +#Fix for opencv and numpy already installed by system + - if [ $TRAVIS_OS_NAME == osx ]; then rm '/usr/local/bin/f2py'; fi + - if [ $TRAVIS_OS_NAME == osx ]; then rm -r '/usr/local/lib/python2.7/site-packages/numpy'; fi + - if [ $TRAVIS_OS_NAME == osx ]; then brew install homebrew/science/opencv; fi + +# FIX: Now openssl is not linked in /usr/local/include and lib + - if [ $TRAVIS_OS_NAME == osx ]; then ln -s /usr/local/opt/openssl/include/* /usr/local/include/; fi + - if [ $TRAVIS_OS_NAME == osx ]; then ln -s /usr/local/opt/openssl/lib/*.a /usr/local/lib/; fi + - if [ $TRAVIS_OS_NAME == osx ]; then ln -s /usr/local/opt/openssl/lib/*.dylib /usr/local/lib/; fi + # - if [ $TRAVIS_OS_NAME == linux ]; then sudo apt-get update && sudo apt-get install -y llvm-3.4 llvm-3.4-dev; fi # - rvm use $RVM --install --binary --fuzzy # - gem update --system @@ -31,8 +54,9 @@ addons: before_script: - qmake QMAKE_CC=$CC QMAKE_CXX=$CXX CONFIG+=NO_SQLCIPHER CONFIG+=tests -#script: make -script: if [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then make && tests/unittests/unittests >/dev/null 2>&1 ; fi +script: + - if [ $TRAVIS_OS_NAME == linux ] && [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then make && tests/unittests/unittests >/dev/null 2>&1 ; fi + - if [ $TRAVIS_OS_NAME == osx ] && [ "${COVERITY_SCAN_BRANCH}" != 1 ]; then make -j 4 ; fi #after_success: From eb95c6895a17758deb22732cf4e4f6f334b378ca Mon Sep 17 00:00:00 2001 From: thunder2 Date: Thu, 3 Nov 2016 08:32:15 +0100 Subject: [PATCH 51/52] Windows build environment: - Renamed folder build_libs to build-libs - Removed old file stripSVN.sh - Fixed some batch files - Switch from curl to wget - Added Qt environment - Added build.bat to build everything --- .../{build_libs => build-libs}/Makefile | 0 .../{build_libs => build-libs}/build-libs.bat | 4 +- .../{build_libs => build-libs}/clean.bat | 0 .../{build_libs => build-libs}/env.bat | 6 +- .../libxslt-1.1.28-fix.tar.gz | Bin build_scripts/Windows/build.bat | 31 +++ build_scripts/Windows/build/env.bat | 1 - build_scripts/Windows/build/pack.bat | 2 +- build_scripts/Windows/env/env-msys.bat | 3 +- build_scripts/Windows/env/env-qt.bat | 23 ++ build_scripts/Windows/env/env.bat | 6 +- .../Windows/env/tools/prepare-msys.bat | 33 ++- .../Windows/env/tools/prepare-qt.bat | 204 ++++++++++++++++++ .../Windows/env/tools/prepare-tools.bat | 80 ++++--- build_scripts/Windows/qt-cmd.bat | 27 +++ build_scripts/Windows/stripSVN.sh | 12 -- build_scripts/Windows/tools/cecho.bat | 6 + .../tools/download-file-wildcard.bat.bat | 46 ++++ build_scripts/Windows/tools/download-file.bat | 13 ++ 19 files changed, 430 insertions(+), 67 deletions(-) rename build_scripts/Windows/{build_libs => build-libs}/Makefile (100%) rename build_scripts/Windows/{build_libs => build-libs}/build-libs.bat (83%) rename build_scripts/Windows/{build_libs => build-libs}/clean.bat (100%) rename build_scripts/Windows/{build_libs => build-libs}/env.bat (50%) rename build_scripts/Windows/{build_libs => build-libs}/libxslt-1.1.28-fix.tar.gz (100%) create mode 100644 build_scripts/Windows/build.bat create mode 100644 build_scripts/Windows/env/env-qt.bat create mode 100644 build_scripts/Windows/env/tools/prepare-qt.bat create mode 100644 build_scripts/Windows/qt-cmd.bat delete mode 100755 build_scripts/Windows/stripSVN.sh create mode 100644 build_scripts/Windows/tools/cecho.bat create mode 100644 build_scripts/Windows/tools/download-file-wildcard.bat.bat create mode 100644 build_scripts/Windows/tools/download-file.bat diff --git a/build_scripts/Windows/build_libs/Makefile b/build_scripts/Windows/build-libs/Makefile similarity index 100% rename from build_scripts/Windows/build_libs/Makefile rename to build_scripts/Windows/build-libs/Makefile diff --git a/build_scripts/Windows/build_libs/build-libs.bat b/build_scripts/Windows/build-libs/build-libs.bat similarity index 83% rename from build_scripts/Windows/build_libs/build-libs.bat rename to build_scripts/Windows/build-libs/build-libs.bat index 197f0f97f..9dac5c8b5 100644 --- a/build_scripts/Windows/build_libs/build-libs.bat +++ b/build_scripts/Windows/build-libs/build-libs.bat @@ -25,13 +25,13 @@ if errorlevel 1 goto error_env :: Check MSYS environment set MSYSSH=%EnvMSYSPath%\msys\1.0\bin\sh.exe -if not exist "%MSYSSH%" echo Please install MSYS first.& exit /B 1 +if not exist "%MSYSSH%" %cecho% error "Please install MSYS first." & exit /B 1 :: Initialize environment call "%~dp0env.bat" if errorlevel 1 goto error_env -call "%ToolsPath%\msys-path.bat" "%CurPath%" MSYSCurPath +call "%ToolsPath%\msys-path.bat" "%~dp0" MSYSCurPath call "%ToolsPath%\msys-path.bat" "%BuildLibsPath%" MSYSBuildLibsPath if not exist "%BuildLibsPath%" mkdir "%BuildLibsPath%" diff --git a/build_scripts/Windows/build_libs/clean.bat b/build_scripts/Windows/build-libs/clean.bat similarity index 100% rename from build_scripts/Windows/build_libs/clean.bat rename to build_scripts/Windows/build-libs/clean.bat diff --git a/build_scripts/Windows/build_libs/env.bat b/build_scripts/Windows/build-libs/env.bat similarity index 50% rename from build_scripts/Windows/build_libs/env.bat rename to build_scripts/Windows/build-libs/env.bat index affde05f9..e340a6f88 100644 --- a/build_scripts/Windows/build_libs/env.bat +++ b/build_scripts/Windows/build-libs/env.bat @@ -1,13 +1,11 @@ -set CurPath=%~dp0 - :: Check MinGW environment set MinGWPath= call "%ToolsPath%\find-in-path.bat" MinGWPath gcc.exe -if "%MinGWPath%"=="" echo Please run command in the Qt Command Prompt or add the path to MinGW bin folder to PATH variable.& exit /B 1 +if "%MinGWPath%"=="" %cecho% error "Please run command in the Qt Command Prompt or add the path to MinGW bin folder to PATH variable." & exit /B 1 :: Get gcc versions call "%ToolsPath%\get-gcc-version.bat" GCCVersion -if "%GCCVersion%"=="" echo Cannot get gcc version.& exit /B 1 +if "%GCCVersion%"=="" %cecho% error "Cannot get gcc version." & exit /B 1 set BuildLibsPath=%EnvRootPath%\build-libs\gcc-%GCCVersion% diff --git a/build_scripts/Windows/build_libs/libxslt-1.1.28-fix.tar.gz b/build_scripts/Windows/build-libs/libxslt-1.1.28-fix.tar.gz similarity index 100% rename from build_scripts/Windows/build_libs/libxslt-1.1.28-fix.tar.gz rename to build_scripts/Windows/build-libs/libxslt-1.1.28-fix.tar.gz diff --git a/build_scripts/Windows/build.bat b/build_scripts/Windows/build.bat new file mode 100644 index 000000000..48b6be7bb --- /dev/null +++ b/build_scripts/Windows/build.bat @@ -0,0 +1,31 @@ +@echo off + +setlocal + +:: Initialize environment +call "%~dp0env.bat" +if errorlevel 1 goto error_env +call "%EnvPath%\env.bat" +if errorlevel 1 goto error_env + +%cecho% info "Build libraries" +call "%~dp0build-libs\build-libs.bat" auto-copy +if errorlevel 1 %cecho% error "Failed to build libraries." & exit /B %ERRORLEVEL% + +%cecho% info "Build %SourceName%" +call "%~dp0build\build.bat" +if errorlevel 1 %cecho% error "Failed to build %SourceName%." & exit /B %ERRORLEVEL% + +%cecho% info "Pack %SourceName%" +call "%~dp0build\pack.bat" +if errorlevel 1 %cecho% error "Failed to pack %SourceName%." & exit /B %ERRORLEVEL% + +%cecho% info "Build installer" +call "%~dp0build\build-installer.bat" +if errorlevel 1 %cecho% error "Failed to build installer." & exit /B %ERRORLEVEL% + +exit /B 0 + +:error_env +echo Failed to initialize environment. +exit /B 1 diff --git a/build_scripts/Windows/build/env.bat b/build_scripts/Windows/build/env.bat index c4758f0d4..cf25d543b 100644 --- a/build_scripts/Windows/build/env.bat +++ b/build_scripts/Windows/build/env.bat @@ -1,4 +1,3 @@ -set CurPath=%~dp0 set BuildPath=%EnvRootPath%\builds set DeployPath=%EnvRootPath%\deploy diff --git a/build_scripts/Windows/build/pack.bat b/build_scripts/Windows/build/pack.bat index a8e7fdaff..3e8773614 100644 --- a/build_scripts/Windows/build/pack.bat +++ b/build_scripts/Windows/build/pack.bat @@ -169,7 +169,7 @@ if exist "%SourcePath%\libresapi\src\webui" ( rem pack files title Pack - %SourceName%-%RsBuildConfig% [pack files] -"%SevenZipExe%" a -mx=9 -t7z "%Archive%" "%RsDeployPath%\*" +"%EnvSevenZipExe%" a -mx=9 -t7z "%Archive%" "%RsDeployPath%\*" title %COMSPEC% diff --git a/build_scripts/Windows/env/env-msys.bat b/build_scripts/Windows/env/env-msys.bat index 9b1d98620..9b5421032 100644 --- a/build_scripts/Windows/env/env-msys.bat +++ b/build_scripts/Windows/env/env-msys.bat @@ -1,5 +1,5 @@ :: Usage: -:: call find-in-path.bat [reinstall|clean] +:: call env-msys.bat [reinstall|clean] :: Initialize environment call "%~dp0env.bat" @@ -12,5 +12,4 @@ exit /B %ERRORLEVEL% :error_env echo Failed to initialize environment. -endlocal exit /B 1 diff --git a/build_scripts/Windows/env/env-qt.bat b/build_scripts/Windows/env/env-qt.bat new file mode 100644 index 000000000..95b633705 --- /dev/null +++ b/build_scripts/Windows/env/env-qt.bat @@ -0,0 +1,23 @@ +:: Usage: +:: call env-qt4.bat version [reinstall|clean] + +:: Initialize environment +call "%~dp0env.bat" +if errorlevel 1 goto error_env + +set EnvQtBasePath=%EnvRootPath%\qt + +:: Create folders +if not exist "%EnvQtBasePath%" mkdir "%EnvQtBasePath%" + +call "%~dp0tools\prepare-qt.bat" %1 %2 +if errorlevel 1 exit /B %ERRORLEVEL% + +if "%MinGWDir%" NEQ "" set PATH=%MinGWDir%\bin;%PATH% +if "%QtDir%" NEQ "" set PATH=%QtDir%\bin;%PATH% + +exit /B 0 + +:error_env +echo Failed to initialize environment. +exit /B 1 diff --git a/build_scripts/Windows/env/env.bat b/build_scripts/Windows/env/env.bat index d9052b5f3..a243256fc 100644 --- a/build_scripts/Windows/env/env.bat +++ b/build_scripts/Windows/env/env.bat @@ -7,13 +7,16 @@ set EnvToolsPath=%EnvRootPath%\tools set EnvTempPath=%EnvRootPath%\tmp set EnvDownloadPath=%EnvRootPath%\download -set EnvCurlExe=%EnvToolsPath%\curl.exe +::set EnvCurlExe=%EnvToolsPath%\curl.exe +set EnvWgetExe=%EnvToolsPath%\wget.exe set EnvSevenZipExe=%EnvToolsPath%\7z.exe set EnvJomExe=%EnvToolsPath%\jom.exe set EnvSedExe=%EnvToolsPath%\sed.exe set EnvCutExe=%EnvToolsPath%\cut.exe set EnvDependsExe=%EnvToolsPath%\depends.exe set EnvMakeNSISExe=%EnvToolsPath%\NSIS\makensis.exe +set EnvCEchoExe=%EnvToolsPath%\cecho.exe +set cecho=call "%ToolsPath%\cecho.bat" :: Create folders if not exist "%EnvRootPath%" mkdir "%EnvRootPath%" @@ -25,5 +28,4 @@ exit /B %ERRORLEVEL% :error_env echo Failed to initialize environment. -endlocal exit /B 1 diff --git a/build_scripts/Windows/env/tools/prepare-msys.bat b/build_scripts/Windows/env/tools/prepare-msys.bat index 4799715ca..af9b9bf78 100644 --- a/build_scripts/Windows/env/tools/prepare-msys.bat +++ b/build_scripts/Windows/env/tools/prepare-msys.bat @@ -9,7 +9,7 @@ if not exist "%EnvRootPath%"=="" exit /B 1 copy "%~dp0root\update-msys.bat" "%EnvRootPath%" >nul if "%~1"=="clean" ( - echo Clean MSYS + %cecho% info "Clean MSYS" call "%ToolsPath%\remove-dir.bat" "%EnvMSYSPath%" goto exit ) @@ -24,23 +24,25 @@ if exist "%EnvMSYSPath%\bin\mingw-get.exe" ( ) set MSYSInstall=mingw-get-0.6.2-mingw32-beta-20131004-1-bin.zip +set MSYSUrl=http://sourceforge.net/projects/mingw/files/Installer/mingw-get/mingw-get-0.6.2-beta-20131004-1/%MSYSInstall%/download set CMakeInstall=cmake-3.1.0-win32-x86.zip +set CMakeUrl=http://www.cmake.org/files/v3.1/%CMakeInstall% set CMakeUnpackPath=%EnvMSYSPath%\msys\1.0 -echo Remove previous MSYS version +%cecho% info "Remove previous MSYS version" call "%ToolsPath%\remove-dir.bat" "%EnvMSYSPath%" -echo Download installation files -if not exist "%EnvDownloadPath%\%MSYSInstall%" "%EnvCurlExe%" -L -k http://sourceforge.net/projects/mingw/files/Installer/mingw-get/mingw-get-0.6.2-beta-20131004-1/%MSYSInstall%/download -o "%EnvDownloadPath%\%MSYSInstall%" -if not exist "%EnvDownloadPath%%\MSYSInstall%" echo Cannot download MSYS& goto error +%cecho% info "Download installation files" +if not exist "%EnvDownloadPath%\%MSYSInstall%" call "%ToolsPath%\download-file.bat" "%MSYSUrl%" "%EnvDownloadPath%\%MSYSInstall%" +if not exist "%EnvDownloadPath%\%MSYSInstall%" %cecho% error "Cannot download MSYS" & goto error -if not exist "%EnvDownloadPath%\%CMakeInstall%" "%EnvCurlExe%" -L -k http://www.cmake.org/files/v3.1/cmake-3.1.0-win32-x86.zip -o "%EnvDownloadPath%\%CMakeInstall%" -if not exist "%EnvDownloadPath%\%CMakeInstall%" echo Cannot download CMake& goto error +if not exist "%EnvDownloadPath%\%CMakeInstall%" call "%ToolsPath%\download-file.bat" "%CMakeUrl%" "%EnvDownloadPath%\%CMakeInstall%" +if not exist "%EnvDownloadPath%\%CMakeInstall%" %cecho% error "Cannot download CMake" & goto error -echo Unpack MSYS +%cecho% info "Unpack MSYS" "%EnvSevenZipExe%" x -o"%EnvMSYSPath%" "%EnvDownloadPath%\%MSYSInstall%" -echo Install MSYS +%cecho% info "Install MSYS" if not exist "%EnvMSYSPath%\var\lib\mingw-get\data\profile.xml" copy "%EnvMSYSPath%\var\lib\mingw-get\data\defaults.xml" "%EnvMSYSPath%\var\lib\mingw-get\data\profile.xml" pushd "%EnvMSYSPath%\bin" mingw-get.exe install mingw32-mingw-get @@ -53,14 +55,14 @@ mingw-get.exe install msys-mktemp mingw-get.exe install msys-wget popd -echo Unpack CMake +%cecho% info "Unpack CMake" "%EnvSevenZipExe%" x -o"%CMakeUnpackPath%" "%EnvDownloadPath%\%CMakeInstall%" -echo Install CMake +%cecho% info "Install CMake" set CMakeVersion= for /D %%F in (%CMakeUnpackPath%\cmake*) do set CMakeVersion=%%~nxF -if "%CMakeVersion%"=="" echo CMake version not found.& goto :exit -echo Found CMake version %CMakeVersion% +if "%CMakeVersion%"=="" %cecho% error "CMake version not found." & goto :exit +%cecho% info "Found CMake version %CMakeVersion%" set FoundProfile= for /f "tokens=3" %%F in ('find /c /i "%CMakeVersion%" "%EnvMSYSPath%\msys\1.0\etc\profile"') do set FoundProfile=%%F @@ -76,8 +78,3 @@ exit /B 0 :error endlocal exit /B 1 - -:error_vars -echo Failed to initialize variables. -endlocal -exit /B 1 diff --git a/build_scripts/Windows/env/tools/prepare-qt.bat b/build_scripts/Windows/env/tools/prepare-qt.bat new file mode 100644 index 000000000..31c938f77 --- /dev/null +++ b/build_scripts/Windows/env/tools/prepare-qt.bat @@ -0,0 +1,204 @@ +:: Usage: +:: call prepare-qt.bat version [reinstall|clean] + +setlocal enabledelayedexpansion + +if "%EnvQtBasePath%"=="" exit /B 1 +if not exist "%EnvRootPath%"=="" exit /B 1 + +set EnvQtVersion=%~1 +if "%EnvQtVersion%"=="" ( + %cecho% error "Please specify Qt version" + goto error +) + +for /f "tokens=1,2 delims=." %%A in ("%EnvQtVersion%") do set EnvQtMainVersion=%%A& set EnvQtBaseVersion=%%A.%%B +set EnvQtPath=%EnvQtBasePath%\%EnvQtVersion% + +if "%~2"=="clean" ( + %cecho% info "Clean Qt %EnvQtVersion%" + call "%ToolsPath%\remove-dir.bat" "%EnvQtPath%" + goto exit +) + +set CheckQmakeExe= +if "%EnvQtMainVersion%"=="4" ( + set CheckQmakeExe=%EnvQtPath%\Qt\bin\qmake.exe +) else ( + if "%EnvQtMainVersion%" GEQ "5" ( + call :get_mingw_version EnvQtMinGWVersion "%EnvQtPath%\%EnvQtBaseVersion%" + if "!EnvQtMinGWVersion!" NEQ "" ( + set CheckQmakeExe=%EnvQtPath%\%EnvQtBaseVersion%\!EnvQtMinGWVersion!\bin\qmake.exe + ) + ) +) + +if "%CheckQmakeExe%" NEQ "" ( + if exist "%CheckQmakeExe%" ( + if "%~2"=="reinstall" ( + choice /M "Found existing Qt %EnvQtVersion% version. Do you want to proceed?" + if !ERRORLEVEL!==2 goto exit + ) else ( + goto exit + ) + ) +) + +set QtInstall=qt-opensource-windows-x86-mingw-%EnvQtVersion%.exe +set QtInstallWildcard=qt-opensource-windows-x86-mingw*-%EnvQtVersion%.exe +set QtUrl=http://download.qt.io/official_releases/qt/%EnvQtBaseVersion%/%EnvQtVersion% + +%cecho% info "Remove previous Qt %EnvQtVersion% version" +call "%ToolsPath%\remove-dir.bat" "%EnvQtPath%" + +%cecho% info "Download Qt installation files" +if not exist "%EnvDownloadPath%\%QtInstall%" ( + call "%ToolsPath%\download-file-wildcard.bat" "%QtUrl%" "%QtInstallWildcard%" "%EnvDownloadPath%" QtInstallDownload + if "!QtInstallDownload!"=="" %cecho% error "Cannot download Qt %EnvQtVersion%" & goto error + ren "%EnvDownloadPath%\!QtInstallDownload!" "%QtInstall%" +) +if not exist "%EnvDownloadPath%\%QtInstall%" %cecho% error "Cannot download Qt %EnvQtVersion%" & goto error + +mkdir "%EnvQtPath%" + +if "%EnvQtMainVersion%"=="4" ( + rem Qt 4 + goto install_qt4 +) +if "%EnvQtMainVersion%" GEQ "5" ( + rem Qt >= 5 + goto install_qt5 +) + +%cecho% error "Unknown Qt version %EnvQtVersion%" + +:error +endlocal & set QtDir=& set MinGWDir= +exit /B 1 + +:exit +set QtDir= +set MinGWDir= + +if "%EnvQtMainVersion%"=="4" ( + rem Qt 4 + set QtDir=%EnvQtBasePath%\%EnvQtVersion%\Qt + set MinGWDir=%EnvQtBasePath%\%EnvQtVersion%\mingw32 +) else ( + if "%EnvQtMainVersion%" GEQ "5" ( + call :get_mingw_version EnvQtToolsMinGWVersion "%EnvQtPath%\Tools" + + set QtDir=%EnvQtPath%\%EnvQtBaseVersion%\!EnvQtMinGWVersion! + set MinGWDir=%EnvQtPath%\Tools\!EnvQtToolsMinGWVersion! + ) +) + +endlocal & set QtDir=%QtDir%& set MinGWDir=%MinGWDir% +exit /B 0 + +:get_mingw_version +setlocal enabledelayedexpansion +set Variable=%~1 +set Result= + +for /D %%A in (%~2\*) do set Name=%%~nA& if "!Name:~0,5!"=="mingw" set Result=!Name! +endlocal & set %Variable%=%Result% +goto :EOF + +:replace +set InFile=%~1 +set InFileName=%~nx1 +set OutFile=%~1.tmp +set SearchText=%~2 +set ReplaceText=%~3 + +if exist "%OutFile%" del /Q "%OutFile%" + +for /f "tokens=1* delims=]" %%A in ('find /n /v ""^<%InFile%') do ( + set string=%%B + + if "!string!"=="" ( + echo.>>%OutFile% + ) else ( + set modified=!string:%SearchText%=%ReplaceText%! + echo !modified!>> %OutFile% + ) +) +del "%InFile%" +rename "%OutFile%" "%InFileName%" +goto :EOF + +:install_qt4 +set MinGWInstall=i686-4.8.2-release-posix-dwarf-rt_v3-rev3.7z +set MinGWUrl=http://sourceforge.net/projects/mingw-w64/files/Toolchains targetting Win32/Personal Builds/mingw-builds/4.8.2/threads-posix/dwarf/%MinGWInstall%/download + +%cecho% info "Download MinGW installation files" +if not exist "%EnvDownloadPath%\%MinGWInstall%" call "%ToolsPath%\download-file.bat" "%MinGWUrl%" "%EnvDownloadPath%\%MinGWInstall%" +if not exist "%EnvDownloadPath%\%MinGWInstall%" %cecho% error "Cannot download MinGW" & goto error + +%cecho% info "Unpack Qt %EnvQtVersion%" +call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" +mkdir "%EnvTempPath%" +"%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%QtInstall%" $_14_ +move "%EnvTempPath%\$_14_" "%EnvQtPath%\Qt" +call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" + +%cecho% info "Unpack MinGW" +"%EnvSevenZipExe%" x -o"%EnvQtPath%" "%EnvDownloadPath%\%MinGWInstall%" + +echo Prepare Qt %EnvQtVersion% +echo [Paths]>"%EnvQtPath%\Qt\bin\qt.conf" +echo Prefix=..>>"%EnvQtPath%\Qt\bin\qt.conf" + +goto exit + +:install_qt5 +set EnvQtInstallerFrameworkVersion=2.0.3 + +set QtInstallerFrameworkInstall=QtInstallerFramework-%EnvQtInstallerFrameworkVersion%-win-x86.exe +set QtInstallerFrameworkUrl=http://download.qt.io/official_releases/qt-installer-framework/%EnvQtInstallerFrameworkVersion%/QtInstallerFramework-win-x86.exe + +%cecho% info "Download QtInstallerFramework installation files" +if not exist "%EnvDownloadPath%\%QtInstallerFrameworkInstall%" call "%ToolsPath%\download-file.bat" "%QtInstallerFrameworkUrl%" "%EnvDownloadPath%\%QtInstallerFrameworkInstall%" +if not exist "%EnvDownloadPath%\%QtInstallerFrameworkInstall%" %cecho% error "Cannot download Qt Installer Framework %EnvQtInstallerFrameworkVersion%" & goto error + +%cecho% info "Unpack Qt Installer Framework" +call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" +mkdir "%EnvTempPath%" +"%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%QtInstallerFrameworkInstall%" bin\devtool.exe +move "%EnvTempPath%\bin\devtool.exe" "%EnvQtPath%" +call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" + +%cecho% info "Unpack Qt %EnvQtVersion%" +call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" +mkdir "%EnvTempPath%" +"%EnvQtPath%\devtool.exe" "%EnvDownloadPath%\%QtInstall%" --dump "%EnvTempPath%" + +pushd "%EnvTempPath%" +del /S *vcredist*.7z +del /S *qtcreator*.7z +del /S *1installer-changelog.7z +for /R %%F in (*.7z) do "%EnvSevenZipExe%" x -y -o"%EnvQtPath%" "%%F" +popd + +call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" + +call :get_mingw_version EnvQtMinGWVersion "%EnvQtPath%\%EnvQtBaseVersion%" + +%cecho% info "Prepare Qt %EnvQtVersion%" +echo [Paths]>"%EnvQtPath%\%EnvQtBaseVersion%\%EnvQtMinGWVersion%\bin\qt.conf" +echo Documentation=../../Docs/Qt-%EnvQtBaseVersion%>>"%EnvQtPath%\%EnvQtBaseVersion%\%EnvQtMinGWVersion%\bin\qt.conf" +echo Examples=../../Examples/Qt-%EnvQtBaseVersion%>>"%EnvQtPath%\%EnvQtBaseVersion%\%EnvQtMinGWVersion%\bin\qt.conf" +echo Prefix=..>>"%EnvQtPath%\%EnvQtBaseVersion%\%EnvQtMinGWVersion%\bin\qt.conf" + +call :replace "%EnvQtPath%\%EnvQtBaseVersion%\%EnvQtMinGWVersion%\mkspecs\qconfig.pri" "Enterprise" "OpenSource" + +for /R "%EnvQtPath%\%EnvQtBaseVersion%\%EnvQtMinGWVersion%\lib" %%A in (*.pc) do ( + call :replace "%%A" "c:/Users/qt/work/install" "%EnvQtPath:\=\\%\%EnvQtBaseVersion%\\%EnvQtMinGWVersion%" + call :replace "%%A" "c:\Users\qt\work\install" "%EnvQtPath:\=/%\%EnvQtBaseVersion%/%EnvQtMinGWVersion%" +) +for /R "%EnvQtPath%\%EnvQtBaseVersion%\%EnvQtMinGWVersion%\lib" %%A in (*.prl) do ( + call :replace "%%A" "c:/Users/qt/work/install" "%EnvQtPath:\=\\%\%EnvQtBaseVersion%\\%EnvQtMinGWVersion%" + call :replace "%%A" "c:\Users\qt\work\install" "%EnvQtPath:\=/%\%EnvQtBaseVersion%/%EnvQtMinGWVersion%" +) +goto exit diff --git a/build_scripts/Windows/env/tools/prepare-tools.bat b/build_scripts/Windows/env/tools/prepare-tools.bat index f453f35da..94ad1ae8b 100644 --- a/build_scripts/Windows/env/tools/prepare-tools.bat +++ b/build_scripts/Windows/env/tools/prepare-tools.bat @@ -2,10 +2,14 @@ setlocal if "%EnvRootPath%"=="" exit /B 1 +set CEchoUrl=https://github.com/lordmulder/cecho/releases/download/2015-10-10/cecho.2015-10-10.zip +set CEchoInstall=cecho.2015-10-10.zip set SevenZipUrl=http://7-zip.org/a/7z1602.msi set SevenZipInstall=7z1602.msi -set CurlUrl=https://bintray.com/artifact/download/vszakats/generic/curl-7.50.1-win32-mingw.7z -set CurlInstall=curl-7.50.1-win32-mingw.7z +::set CurlUrl=https://bintray.com/artifact/download/vszakats/generic/curl-7.50.1-win32-mingw.7z +::set CurlInstall=curl-7.50.1-win32-mingw.7z +set WgetUrl=https://eternallybored.org/misc/wget/current/wget.exe +set WgetInstall=wget.exe set JomUrl=http://download.qt.io/official_releases/jom/jom.zip set JomInstall=jom.zip set DependsUrl=http://www.dependencywalker.com/depends22_x86.zip @@ -33,32 +37,58 @@ if not exist "%EnvToolsPath%\7z.exe" ( call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" ) -if not exist "%EnvToolsPath%\curl.exe" ( +if not exist "%EnvToolsPath%\cecho.exe" ( call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" mkdir "%EnvTempPath%" - echo Download Curl installation + echo Download cecho installation - if not exist "%EnvDownloadPath%\%CurlInstall%" call "%ToolsPath%\winhttpjs.bat" %CurlUrl% -saveTo "%EnvDownloadPath%\%CurlInstall%" - if not exist "%EnvDownloadPath%\%CurlInstall%" echo Cannot download Curl installation& goto error + if not exist "%EnvDownloadPath%\%CEchoInstall%" call "%ToolsPath%\winhttpjs.bat" "%CEchoUrl%" -saveTo "%EnvDownloadPath%\%CEchoInstall%" + if not exist "%EnvDownloadPath%\%cCEhoInstall%" echo Cannot download cecho installation& goto error - echo Unpack Curl - "%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%CurlInstall%" - copy "%EnvTempPath%\curl-7.50.1-win32-mingw\bin\curl.exe" "%EnvToolsPath%" + echo Unpack cecho + "%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%CEchoInstall%" + copy "%EnvTempPath%\cecho.exe" "%EnvToolsPath%" call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" ) +::if not exist "%EnvToolsPath%\curl.exe" ( +:: call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" +:: mkdir "%EnvTempPath%" +:: +:: echo Download Curl installation +:: +:: if not exist "%EnvDownloadPath%\%CurlInstall%" call "%ToolsPath%\winhttpjs.bat" %CurlUrl% -saveTo "%EnvDownloadPath%\%CurlInstall%" +:: if not exist "%EnvDownloadPath%\%CurlInstall%" echo Cannot download Curl installation& goto error +:: +:: echo Unpack Curl +:: "%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%CurlInstall%" +:: copy "%EnvTempPath%\curl-7.50.1-win32-mingw\bin\curl.exe" "%EnvToolsPath%" +:: +:: call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" +::) + +if not exist "%EnvToolsPath%\wget.exe" ( + %cecho% info "Download Wget installation" + + if not exist "%EnvDownloadPath%\%WgetInstall%" call "%ToolsPath%\winhttpjs.bat" %WgetUrl% -saveTo "%EnvDownloadPath%\%WgetInstall%" + if not exist "%EnvDownloadPath%\%WgetInstall%" %cecho% error "Cannot download Wget installation" & goto error + + %cecho% info "Copy Wget" + copy "%EnvDownloadPath%\wget.exe" "%EnvToolsPath%" +) + if not exist "%EnvToolsPath%\jom.exe" ( call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" mkdir "%EnvTempPath%" - echo Download jom installation + %cecho% info "Download jom installation" if not exist "%EnvDownloadPath%\%JomInstall%" call "%ToolsPath%\winhttpjs.bat" %JomUrl% -saveTo "%EnvDownloadPath%\%JomInstall%" - if not exist "%EnvDownloadPath%\%JomInstall%" echo Cannot download jom installation& goto error + if not exist "%EnvDownloadPath%\%JomInstall%" %cecho% error "Cannot download jom installation" & goto error - echo Unpack jom + %cecho% info "Unpack jom" "%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%JomInstall%" copy "%EnvTempPath%\jom.exe" "%EnvToolsPath%" @@ -69,12 +99,12 @@ if not exist "%EnvToolsPath%\depends.exe" ( call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" mkdir "%EnvTempPath%" - echo Download Dependency Walker installation + %cecho% info "Download Dependency Walker installation" if not exist "%EnvDownloadPath%\%DependsInstall%" call "%ToolsPath%\winhttpjs.bat" %DependsUrl% -saveTo "%EnvDownloadPath%\%DependsInstall%" - if not exist "%EnvDownloadPath%\%DependsInstall%" echo Cannot download Dependendy Walker installation& goto error + if not exist "%EnvDownloadPath%\%DependsInstall%" %cecho% error "Cannot download Dependendy Walker installation" & goto error - echo Unpack Dependency Walker + %cecho% info "Unpack Dependency Walker" "%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%DependsInstall%" copy "%EnvTempPath%\*" "%EnvToolsPath%" @@ -85,12 +115,12 @@ if not exist "%EnvToolsPath%\cut.exe" ( call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" mkdir "%EnvTempPath%" - echo Download Unix Tools installation + %cecho% info "Download Unix Tools installation" if not exist "%EnvDownloadPath%\%UnixToolsInstall%" call "%ToolsPath%\winhttpjs.bat" %UnixToolsUrl% -saveTo "%EnvDownloadPath%\%UnixToolsInstall%" - if not exist "%EnvDownloadPath%\%UnixToolsInstall%" echo Cannot download unix Tools installation& goto error + if not exist "%EnvDownloadPath%\%UnixToolsInstall%" %cecho% error ""Cannot download Unix Tools installation" & goto error - echo Unpack Unix Tools + %cecho% info "Unpack Unix Tools" "%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%UnixToolsInstall%" copy "%EnvTempPath%\cut.exe" "%EnvToolsPath%" @@ -101,12 +131,12 @@ if not exist "%EnvToolsPath%\sed.exe" ( call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" mkdir "%EnvTempPath%" - echo Download Unix Tools installation + %cecho% info "Download Unix Tools installation" if not exist "%EnvDownloadPath%\%UnixToolsInstall%" call "%ToolsPath%\winhttpjs.bat" %UnixToolsUrl% -saveTo "%EnvDownloadPath%\%UnixToolsInstall%" - if not exist "%EnvDownloadPath%\%UnixToolsInstall%" echo Cannot download Unix Tools installation& goto error + if not exist "%EnvDownloadPath%\%UnixToolsInstall%" %cecho% error ""Cannot download Unix Tools installation" & goto error - echo Unpack Unix Tools + %cecho% info "Unpack Unix Tools" "%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%UnixToolsInstall%" copy "%EnvTempPath%\sed.exe" "%EnvToolsPath%" @@ -117,12 +147,12 @@ if not exist "%EnvToolsPath%\NSIS\nsis.exe" ( call "%ToolsPath%\remove-dir.bat" "%EnvTempPath%" mkdir "%EnvTempPath%" - echo Download NSIS installation + %cecho% info "Download NSIS installation" - if not exist "%EnvDownloadPath%\%NSISInstall%" "%EnvCurlExe%" -L -k %NSISUrl% -o "%EnvDownloadPath%\%NSISInstall%" - if not exist "%EnvDownloadPath%\%NSISInstall%" echo Cannot download NSIS installation& goto error + if not exist "%EnvDownloadPath%\%NSISInstall%" call "%ToolsPath%\download-file.bat" "%NSISUrl%" "%EnvDownloadPath%\%NSISInstall%" + if not exist "%EnvDownloadPath%\%NSISInstall%" %cecho% error "Cannot download NSIS installation" & goto error - echo Unpack NSIS + %cecho% info "Unpack NSIS" "%EnvSevenZipExe%" x -o"%EnvTempPath%" "%EnvDownloadPath%\%NSISInstall%" if not exist "%NSISInstallPath%" mkdir "%NSISInstallPath%" xcopy /s "%EnvTempPath%" "%NSISInstallPath%" diff --git a/build_scripts/Windows/qt-cmd.bat b/build_scripts/Windows/qt-cmd.bat new file mode 100644 index 000000000..1e4ad475e --- /dev/null +++ b/build_scripts/Windows/qt-cmd.bat @@ -0,0 +1,27 @@ +:: Usage: +:: call qt-cmd.bat [command] + +@echo off + +setlocal + +set QtVersion=%~1 + +:: Initialize environment +call "%~dp0env.bat" +if errorlevel 1 goto error_env +call "%EnvPath%\env-qt.bat" %QtVersion% +if errorlevel 1 goto error_env + +if "%~2"=="" ( + "%ComSpec%" +) else ( + "%ComSpec%" /c %2 %3 %4 %5 %6 %7 %8 %9 +) + +exit /B %ERRORLEVEL% + +:error_env +echo Failed to initialize environment. +endlocal +exit /B 1 diff --git a/build_scripts/Windows/stripSVN.sh b/build_scripts/Windows/stripSVN.sh deleted file mode 100755 index 65a740cab..000000000 --- a/build_scripts/Windows/stripSVN.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - - -if [ $# -le 0 ] -then - echo usage $0 directory - exit -fi - -echo find $1 -name .svn -rm -vrf `find $1 -name .svn` - diff --git a/build_scripts/Windows/tools/cecho.bat b/build_scripts/Windows/tools/cecho.bat new file mode 100644 index 000000000..69c6370e9 --- /dev/null +++ b/build_scripts/Windows/tools/cecho.bat @@ -0,0 +1,6 @@ +:: Usage: +:: call cecho.bat [info|error|std] "text" + +if "%~1"=="std" echo %~2 +if "%~1"=="info" "%EnvCEchoExe%" green "%~2" +if "%~1"=="error" "%EnvCEchoExe%" red "%~2" diff --git a/build_scripts/Windows/tools/download-file-wildcard.bat.bat b/build_scripts/Windows/tools/download-file-wildcard.bat.bat new file mode 100644 index 000000000..d37943063 --- /dev/null +++ b/build_scripts/Windows/tools/download-file-wildcard.bat.bat @@ -0,0 +1,46 @@ +:: Usage: +:: call download-file-wildcard.bat url file-wildcard download-path variable + +if "%~4"=="" ( + echo. + echo Parameter error. + exit /B 1 +) + +if "%EnvTempPath%"=="" ( + echo. + echo Environment error. + exit /B 1 +) + +setlocal + +set Url=%~1 +set FileWildcard=%~2 +set DownloadPath=%~3 +set Var=%~4 +set File= + +call "%~dp0remove-dir.bat" "%EnvTempPath%" +mkdir "%EnvTempPath%" + +"%EnvWgetExe%" --recursive --continue --no-directories --no-parent -A "%FileWildcard%" --directory-prefix="%EnvTempPath%" "%Url%" + +if errorlevel 1 ( + call "%~dp0remove-dir.bat" "%EnvTempPath%" + endlocal & set %Var%= + exit /B %ERRORLEVEL% +) + +for %%A in (%EnvTempPath%\%FileWildcard%) do set File=%%~nxA +if "%File%"=="" ( + call "%~dp0remove-dir.bat" "%EnvTempPath%" + endlocal & set %Var%= + exit /B %ERRORLEVEL% +) + +move "%EnvTempPath%\%File%" "%DownloadPath%" +call "%~dp0remove-dir.bat" "%EnvTempPath%" + +endlocal & set %Var%=%File% +exit /B 0 diff --git a/build_scripts/Windows/tools/download-file.bat b/build_scripts/Windows/tools/download-file.bat new file mode 100644 index 000000000..d42349ccb --- /dev/null +++ b/build_scripts/Windows/tools/download-file.bat @@ -0,0 +1,13 @@ +:: Usage: +:: call download-file.bat url file + +if "%~2"=="" ( + echo. + echo Parameter error. + exit /B 1 +) + +::"%EnvCurlExe%" -L -k "%~1" -o "%~2" +"%EnvWgetExe%" --continue "%~1" --output-document="%~2" + +exit /B %ERRORLEVEL% From 461975f11533edae12f7b1150101fe333fb45da3 Mon Sep 17 00:00:00 2001 From: cyril soler Date: Mon, 7 Nov 2016 10:09:28 +0100 Subject: [PATCH 52/52] generally prevent threads to start twice, and fixed bug causing DirWatcher to be run twice --- libretroshare/src/file_sharing/directory_updater.cc | 6 +++--- libretroshare/src/util/rsthreads.cc | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/libretroshare/src/file_sharing/directory_updater.cc b/libretroshare/src/file_sharing/directory_updater.cc index de92c6ee1..331e51822 100644 --- a/libretroshare/src/file_sharing/directory_updater.cc +++ b/libretroshare/src/file_sharing/directory_updater.cc @@ -54,10 +54,10 @@ void LocalDirectoryUpdater::setEnabled(bool b) if(mIsEnabled == b) return ; - if(b) - start("fs dir updater") ; - else + if(!b) shutdown(); + else if(!isRunning()) + start("fs dir updater") ; mIsEnabled = b ; } diff --git a/libretroshare/src/util/rsthreads.cc b/libretroshare/src/util/rsthreads.cc index fcf4483be..8cd4a26d6 100644 --- a/libretroshare/src/util/rsthreads.cc +++ b/libretroshare/src/util/rsthreads.cc @@ -157,6 +157,11 @@ void RsTickingThread::fullstop() void RsThread::start(const std::string &threadName) { + if(isRunning()) + { + std::cerr << "(EE) RsThread \"" << threadName << "\" is already running. Will not start twice!" << std::endl; + return ; + } pthread_t tid; void *data = (void *)this ;