2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2004 Net Integration Technologies, Inc.
5 * WvTFTPBase, the WvTFTP base class. This class holds functions that are
6 * common to both server and client (if one is ever written).
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #ifndef __WVTFTPBASE_H
24 #define __WVTFTPBASE_H
27 #include "wvhashtable.h"
30 #include "wvtimestream.h"
31 #include "wvstringlist.h"
37 const int MAX_PACKET_SIZE
= 65535;
38 const bool WVTFTP_DEBUG
= false;
43 PktTime(int _pktclump
);
46 void set(int pktnum
, struct timeval
&tv
);
47 struct timeval
*get(int pktnum
);
52 struct timeval
*times
;
55 class WvTFTPBase
: public WvUDPStream
58 enum TFTPDir
{tftpread
= 0, tftpwrite
= 1};
59 enum TFTPOpcode
{RRQ
= 1, WRQ
= 2, DATA
= 3, ACK
= 4, ERROR
= 5};
60 enum TFTPMode
{netascii
= 0, octet
, mail
};
62 // _tftp_tick is in ms.
63 WvTFTPBase(int _tftp_tick
, int port
= 0);
64 virtual ~WvTFTPBase();
68 WvIPPortAddr remote
; // remote's address and port
69 WvString filename
; // filename of this connection
70 TFTPDir direction
; // reading or writing?
71 TFTPMode mode
; // mode (netascii or octet)
72 FILE *tftpfile
; // the file being transferred
73 size_t blksize
; // blocksize (RFC 2348)
74 int tsize
; // transfer size (RFC 2349)
75 int pktclump
; // number of packets to send at once
76 int unack
; // first unacked packet for writing data
77 int lastsent
; // block number of last packet sent
78 bool donefile
; // done reading from the file?
79 bool send_oack
; // do we need to or did we send an OACK?
80 char oack
[512]; // Holds the OACK packet in case we need
81 size_t oacklen
; // to resend it.
83 int rtt
; // "Total" round-trip time accumulator.
84 int mult
; // base of the multiplier for timeout
85 // backoffs. The actual multiplier
88 int total_packets
; // Number of correct packets used to
89 // calculate average rtt.
91 int timed_out_ignore
; // block number of largest packet that
92 // has been retransmitted due to
93 // timeout, and should thus be ignored
94 // in rtt calculations.
95 struct timeval last_received
; // Time the last packet was received.
115 DeclareWvDict(TFTPConn
, WvIPPortAddr
, remote
);
121 char packet
[MAX_PACKET_SIZE
];
125 virtual void new_connection() = 0;
126 virtual void handle_packet();
127 void send_data(TFTPConn
*c
, bool resend
= false);
128 void send_ack(TFTPConn
*c
, bool resend
= false);
129 void send_err(char errcode
, WvString errmsg
= "");