1.1 --- a/src/ltp.cc Thu Mar 27 14:51:47 2014 +0000
1.2 +++ b/src/ltp.cc Thu Mar 27 19:32:01 2014 +0000
1.3 @@ -220,6 +220,17 @@
1.4 /// to be saved to CF.
1.5 #define LTP_STATE_CHANGED ltp_state_changed=true;
1.6
1.7 +// SF MUDSAT testing: see what happens if I just set all the segments of this
1.8 +// all green block to indicate they were not sent, but just once
1.9 +int green_re_tx_countdown=2; // move to "global" (gulp:-)
1.10 +
1.11 +// SF MUDSAT testing: default ciphersuite stuff
1.12 +// TODO: fixme
1.13 +static int using_def_crypto=0;
1.14 +static int def_ciphersuite=LTP_CS_SIG;
1.15 +static char *def_keyid="foo";
1.16 +static char *def_crypto_cfg="ltp.crypt";
1.17 +
1.18 /*!
1.19 * @fn ltp_instance ltp_next_instance(void)
1.20 * @return is a new (unused) instance number
1.21 @@ -337,6 +348,26 @@
1.22 * @section sfunctions static functions from here on down.
1.23 */
1.24
1.25 +// SF MUDSAT testing: see what happens if I just set all the segments of this
1.26 +// all green block to indicate they were not sent, but just once
1.27 +int ltp_green_re_tx(ltp_segment *seg)
1.28 +{
1.29 +
1.30 + int blockid=seg->parent->id;
1.31 + ltp_segment *segments=ltp_state_var.txq.segments;
1.32 +
1.33 + // go through all segments for that block and set their
1.34 + // state to LTP_PS_WAITING_SEND and see what happens
1.35 +
1.36 + for (int i=0;i!=ltp_state_var.txq.nsegments;i++) {
1.37 + if (segments[i].parent->id==blockid) {
1.38 + // mark for re-tx
1.39 + segments[i].state=LTP_PS_WAITING_SEND;
1.40 + }
1.41 + }
1.42 +
1.43 + return(LTP_OK);
1.44 +}
1.45
1.46 /*!
1.47 * @brief estimate the length of stuff extension encodings take up
1.48 @@ -674,11 +705,23 @@
1.49 *added_len+=ck->cval.len+10; // overestimate but ok
1.50 }
1.51
1.52 + // SF: MUDSAT - just keep any existing authenticators
1.53 + // and don't recalculate 'em (nothing ought change I hope)
1.54 + int already_authed=0;
1.55 + for (int oe=0;oe!=seg->nexts;oe++) {
1.56 + if (seg->exts[oe].type==LTPE_AUTH) {
1.57 + already_authed=1;
1.58 + *added_len+=100; // TODO: fix this later, 100 is loads though
1.59 + }
1.60 + }
1.61 +
1.62 // now we see what, if anything to do about outbound authentication
1.63 - if (sock->opts.auth.ciphersuite!=LTP_CS_NONE) {
1.64 + if (!already_authed && sock->opts.auth.ciphersuite!=LTP_CS_NONE) {
1.65 // something!
1.66 int enclen,authlen;
1.67 unsigned char *encbuf,*authbuf;
1.68 +
1.69 +
1.70 // put in anything that's part of plaintext
1.71 rv=add_ext(seg);
1.72 if (rv<=0) LTPERR(rv-1); // the -1 makes sure to not return zero
1.73 @@ -734,6 +777,16 @@
1.74 theext->enclen=0;
1.75 theext->encval=NULL;
1.76 ptbuf.len+=kblen+10;
1.77 + // SF: MUDSAT testing - this is not an addition but a bugfix
1.78 + // if there are existing extensions then we need to allow
1.79 + // space for their encoding in the ptbuf
1.80 + int otherextslen=0;
1.81 + for (int oe=0;oe!=seg->nexts;oe++) {
1.82 + int a=seg->exts[oe].len;
1.83 + int b=seg->exts[oe].enclen;
1.84 + otherextslen+=max(a,b)*2;
1.85 + }
1.86 + ptbuf.len+=otherextslen;
1.87 ptbuf.val=ltpc_alloc(ptbuf.len);
1.88 if (!ptbuf.val) LTPERR(LTP_MEMORY);
1.89 rv=ltpc_encode(seg, (int*)&ptbuf.len, ptbuf.val, true);
1.90 @@ -754,7 +807,7 @@
1.91 theext->val=(void*)tlr;
1.92
1.93 // accumulate more space
1.94 - *added_len+=kblen+authlen+32; // overestimate but ok
1.95 + *added_len+=kblen+authlen+1000; // overestimate but ok
1.96 }
1.97 if (sock->ltptrelay) {
1.98 rv=ltpt_add_departure_exts(seg,block,sock);
1.99 @@ -2536,6 +2589,20 @@
1.100 sockets[nsockets-1].ltptrelay=false;
1.101 sockets[nsockets-1].close_called=false;
1.102
1.103 + // SF: MUDSAT - use default crypto
1.104 + if (using_def_crypto==1) {
1.105 + ltp_auth_so ov;
1.106 + ov.ciphersuite=def_ciphersuite;
1.107 + ov.keyidlen=strlen(def_keyid);
1.108 + memcpy(ov.keyid,def_keyid,ov.keyidlen);
1.109 +#ifdef LTP_VERBOSE
1.110 + snprintf(ltpstr,LTPSTR_LEN,"Setting DEFAULT ciphersuite to %d, keyid to |%s| in ltp_setsockopt\n",
1.111 + ov.ciphersuite,octets2str(ov.keyid,ov.keyidlen));
1.112 + ltp_log(LTP_LOG_ADV,ltpstr);
1.113 +#endif
1.114 + sockets[nsockets-1].opts.auth=ov;
1.115 + }
1.116 +
1.117 int rv=init_inactivity_timer(LTP_PARENT_SOCKET,(void*)&sockets[nsockets-1],false);
1.118 if (rv) {
1.119 snprintf(ltpstr,LTPSTR_LEN,"Cannot initialise inactivity timer for socket exiting\n");
1.120 @@ -4393,6 +4460,20 @@
1.121 lowlogscope(s2.nscopes, s2.lbs, s2.ubs, __LINE__, LTP_SUB_SCOPES, 0);
1.122 lowlogscope(res.nscopes, res.lbs, res.ubs, __LINE__, LTP_SUB_SCOPES, 0);
1.123 #endif
1.124 +
1.125 + // SF: MUDSAT
1.126 + // if there's a crypto cfg in the working directory then
1.127 + // use that and set up a ciphersuite
1.128 + // TODO: Parse it out to check
1.129 + FILE *fp=fopen(def_crypto_cfg,"r");
1.130 + if (fp) {
1.131 + // just openable is enough for now
1.132 + fclose(fp);
1.133 + rv=ltp_crypt_setup(def_crypto_cfg);
1.134 + if (rv) LTPERR(rv);
1.135 + using_def_crypto=1;
1.136 + }
1.137 +
1.138 return(LTP_OK);
1.139 }
1.140
1.141 @@ -5177,7 +5258,6 @@
1.142 if (rrv) LTPERR(rrv);
1.143 }
1.144
1.145 - // I *think* we can free up the encoded buffer immediately!!
1.146 if (segments[i].seg.type!=LTPC_SEG_ENCODED) {
1.147 free(l2buf.val);
1.148 }
1.149 @@ -5251,6 +5331,15 @@
1.150 && segments[i].seg.type==LTPC_SEG_DS
1.151 && segments[i].seg.val.ds.eob) {
1.152 segments[i].parent->complete=true;
1.153 +
1.154 + // SF MUDSAT testing: see what happens if I just set all the segments of this
1.155 + // all green block to indicate they were not sent, but just once
1.156 + if (green_re_tx_countdown!=0) {
1.157 + int rtrv=ltp_green_re_tx(&segments[i]);
1.158 + if (rtrv) LTPERR(rtrv);
1.159 + green_re_tx_countdown--;
1.160 + }
1.161 +
1.162 }
1.163 // if that's the last regardless and the redpart is done then we're all done
1.164 if (segments[i].seg.type==LTPC_SEG_DS