1 #ifndef CRYPTOPP_NETWORK_H 2 #define CRYPTOPP_NETWORK_H 6 #ifdef HIGHRES_TIMER_AVAILABLE 18 LimitedBandwidth(lword maxBytesPerSecond = 0)
19 : m_maxBytesPerSecond(maxBytesPerSecond), m_timer(Timer::MILLISECONDS)
20 , m_nextTransceiveTime(0)
21 { m_timer.StartTimer(); }
23 lword GetMaxBytesPerSecond()
const 24 {
return m_maxBytesPerSecond; }
26 void SetMaxBytesPerSecond(lword v)
27 { m_maxBytesPerSecond = v; }
29 lword ComputeCurrentTransceiveLimit();
31 double TimeToNextTransceive();
33 void NoteTransceive(lword size);
42 lword m_maxBytesPerSecond;
44 typedef std::deque<std::pair<double, lword> > OpQueue;
48 double m_nextTransceiveTime;
50 void ComputeNextTransceiveTime();
51 double GetCurTimeAndCleanUp();
59 : m_messageEndSent(
false) , m_doPumpBlocked(
false), m_blockedBySpeedLimit(
false) {Detach(attachment);}
66 size_t GeneralPump2(lword &byteCount,
bool blockingOutput=
true,
unsigned long maxTime=
INFINITE_TIME,
bool checkDelimiter=
false, byte delimiter=
'\n');
68 lword GeneralPump(lword maxSize=LWORD_MAX,
unsigned long maxTime=
INFINITE_TIME,
bool checkDelimiter=
false, byte delimiter=
'\n')
70 GeneralPump2(maxSize,
true, maxTime, checkDelimiter, delimiter);
73 lword TimedPump(
unsigned long maxTime)
74 {
return GeneralPump(LWORD_MAX, maxTime);}
75 lword PumpLine(byte delimiter=
'\n', lword maxSize=1024)
76 {
return GeneralPump(maxSize,
INFINITE_TIME,
true, delimiter);}
78 size_t Pump2(lword &byteCount,
bool blocking=
true)
79 {
return GeneralPump2(byteCount, blocking, blocking ?
INFINITE_TIME : 0);}
80 size_t PumpMessages2(
unsigned int &messageCount,
bool blocking=
true);
84 virtual size_t DoPump(lword &byteCount,
bool blockingOutput,
85 unsigned long maxTime,
bool checkDelimiter, byte delimiter) =0;
87 bool BlockedBySpeedLimit()
const {
return m_blockedBySpeedLimit; }
90 bool m_messageEndSent, m_doPumpBlocked, m_blockedBySpeedLimit;
97 virtual bool MustWaitToReceive() {
return false;}
98 virtual bool MustWaitForResult() {
return false;}
100 virtual bool Receive(byte* buf,
size_t bufLen) =0;
101 virtual unsigned int GetReceiveResult() =0;
102 virtual bool EofReceived()
const =0;
109 virtual size_t GetMaxBufferSize()
const =0;
110 virtual size_t GetCurrentBufferSize()
const =0;
111 virtual bool EofPending()
const =0;
113 virtual float ComputeCurrentSpeed() =0;
115 virtual float GetMaxObservedSpeed()
const =0;
136 lword TimedFlush(
unsigned long maxTime,
size_t targetSize = 0);
138 virtual void SetMaxBufferSize(
size_t maxBufferSize) =0;
140 virtual void SetAutoFlushBound(
size_t bound) =0;
143 virtual lword DoFlush(
unsigned long maxTime,
size_t targetSize) = 0;
145 bool BlockedBySpeedLimit()
const {
return m_blockedBySpeedLimit; }
148 bool m_blockedBySpeedLimit;
155 virtual bool MustWaitToSend() {
return false;}
156 virtual bool MustWaitForResult() {
return false;}
157 virtual void Send(
const byte* buf,
size_t bufLen) =0;
158 virtual unsigned int GetSendResult() =0;
159 virtual bool MustWaitForEof() {
return false;}
160 virtual void SendEof() =0;
161 virtual bool EofSent() {
return false;}
173 bool SourceExhausted()
const {
return m_dataBegin == m_dataEnd && GetReceiver().EofReceived();}
176 size_t DoPump(lword &byteCount,
bool blockingOutput,
unsigned long maxTime,
bool checkDelimiter, byte delimiter);
183 size_t m_putSize, m_dataBegin, m_dataEnd;
184 bool m_waitingForResult, m_outputBlocked;
191 NetworkSink(
unsigned int maxBufferSize,
unsigned int autoFlushBound);
196 size_t Put2(
const byte *inString,
size_t length,
int messageEnd,
bool blocking);
198 void SetMaxBufferSize(
size_t maxBufferSize) {m_maxBufferSize = maxBufferSize; m_buffer.SetNodeSize(
UnsignedMin(maxBufferSize, 16U*1024U+256U));}
201 size_t GetMaxBufferSize()
const {
return m_maxBufferSize;}
202 size_t GetCurrentBufferSize()
const {
return (
size_t)m_buffer.CurrentSize();}
204 void ClearBuffer() { m_buffer.Clear(); }
206 bool EofPending()
const {
return m_eofState > EOF_NONE && m_eofState < EOF_DONE; }
214 lword DoFlush(
unsigned long maxTime,
size_t targetSize);
220 enum EofState { EOF_NONE, EOF_PENDING_SEND, EOF_PENDING_DELIVERY, EOF_DONE };
222 size_t m_maxBufferSize, m_autoFlushBound;
223 bool m_needSendResult, m_wasBlocked;
228 float m_byteCountSinceLastTimerReset, m_currentSpeed, m_maxObservedSpeed;
233 #endif // #ifdef HIGHRES_TIMER_AVAILABLE
container of wait objects
virtual float GetMaxObservedSpeed() const =0
get the maximum observed speed of this sink in bytes per second
void SetAutoFlushBound(size_t bound)
set a bound which will cause sink to flush if exceeded by GetCurrentBufferSize()
virtual float ComputeCurrentSpeed()=0
compute the current speed of this sink in bytes per second
Library configuration file.
SecByteBlock is a SecBlock<byte> typedef.
Interface for objects that can be waited on.
a Sink class that queues input and can flush to a device for a specified amount of time...
const T1 UnsignedMin(const T1 &a, const T2 &b)
Safe comparison of values that could be neagtive and incorrectly promoted.
const unsigned long INFINITE_TIME
Represents infinite time.
Implementation of BufferedTransformation's attachment interface in cryptlib.h.
unsigned int GetMaxWaitObjectCount() const
Implementation of BufferedTransformation's attachment interface.
Provides auto signaling support.
Crypto++ library namespace.
a Source class that can pump from a device for a specified amount of time.