2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2003 Net Integration Technologies, Inc.
5 * WvTFTPBase, the WvTFTP base class. This class holds functions that are
6 * common to both server and client.
12 #include "wvhashtable.h"
15 #include "wvtimestream.h"
16 #include "wvstringlist.h"
21 const int MAX_PACKET_SIZE
= 65535;
22 const bool WVTFTP_DEBUG
= false;
27 PktTime(int _pktclump
);
30 void set(int pktnum
, struct timeval
&tv
);
31 struct timeval
*get(int pktnum
);
36 struct timeval
*times
;
39 class WvTFTPBase
: public WvUDPStream
42 enum TFTPDir
{tftpread
= 0, tftpwrite
= 1};
43 enum TFTPOpcode
{RRQ
= 1, WRQ
= 2, DATA
= 3, ACK
= 4, ERROR
= 5};
44 enum TFTPMode
{netascii
= 0, octet
, mail
};
46 // _tftp_tick is in ms.
47 WvTFTPBase(int _tftp_tick
, int port
= 0);
48 virtual ~WvTFTPBase();
52 WvIPPortAddr remote
; // remote's address and port
53 WvString filename
; // filename of this connection
54 TFTPDir direction
; // reading or writing?
55 TFTPMode mode
; // mode (netascii or octet)
56 FILE *tftpfile
; // the file being transferred
57 size_t blksize
; // blocksize (RFC 2348)
58 int tsize
; // transfer size (RFC 2349)
59 int pktclump
; // number of packets to send at once
60 int unack
; // first unacked packet for writing data
61 int lastsent
; // block number of last packet sent
62 bool donefile
; // done reading from the file?
63 bool send_oack
; // do we need to or did we send an OACK?
64 char oack
[512]; // Holds the OACK packet in case we need
65 size_t oacklen
; // to resend it.
67 int rtt
; // "Total" round-trip time accumulator.
68 int mult
; // base of the multiplier for timeout
69 // backoffs. The actual multiplier
72 int total_packets
; // Number of correct packets used to
73 // calculate average rtt.
75 int timed_out_ignore
; // block number of largest packet that
76 // has been retransmitted due to
77 // timeout, and should thus be ignored
78 // in rtt calculations.
83 { if (tftpfile
) fclose(tftpfile
); if (pkttimes
) delete pkttimes
; }
86 DeclareWvDict(TFTPConn
, WvIPPortAddr
, remote
);
92 char packet
[MAX_PACKET_SIZE
];
96 virtual void new_connection() = 0;
97 virtual void handle_packet();
98 void send_data(TFTPConn
*c
, bool resend
= false);
99 void send_ack(TFTPConn
*c
, bool resend
= false);
100 void send_err(char errcode
, WvString errmsg
= "");