1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_CURVECP_SENT_BLOCK_LIST_H_
6 #define NET_CURVECP_SENT_BLOCK_LIST_H_
11 #include "base/memory/ref_counted.h"
12 #include "base/time.h"
16 class IOBufferWithSize
;
18 // A SentBlockList manages everything needed to track a set of of blocks
19 // which have been sent. It can assign new ids to new blocks, find pending
20 // blocks by id, or discard blocks after they have been acknowledged by the
27 // Creates a new block to be tracked.
28 // On success, returns the unique position of this buffer within the stream,
29 // which can be used to lookup this block later.
30 // Returns -1 if the blocklist is already full.
31 int64
CreateBlock(IOBufferWithSize
* buffer
);
33 // Tracks that a block has been sent.
34 // |position| is the identifier of the block being sent.
35 // |message_id| is the id of the message sent containing the block.
36 // Returns false if no block for |position| exists.
37 bool MarkBlockSent(int64 position
, int64 message_id
);
39 // Acknowledges ranges from |begin_range| to |end_range|.
40 // Partial acknowledgements (e.g. where the ack range spans a partial
41 // block) are not supported.
42 // Removes blocks covered by these ranges from tracking.
43 void AcknowledgeBlocks(int64 begin_range
, int64 end_range
);
45 // Returns a new, unique message id.
46 int64
GetNewMessageId();
48 // Find a block based on its |position|.
49 // Returns the block, if found, or NULL otherwise.
50 IOBufferWithSize
* FindBlockByPosition(int64 position
) const;
52 // Find the last send time of a block, based the id of the last
53 // message to send it.
54 base::TimeTicks
FindLastSendTime(int64 last_message_id
) const;
56 // Returns the position of the oldest sent block.
57 int64
FindPositionOfOldestSentBlock() const;
59 // Returns the number of blocks in the list.
60 size_t size() const { return list_
.size(); }
62 // Returns true if the list is full and cannot take new blocks.
66 // An UnackedBlock is a block of application data which has been sent in a
67 // message, but not acknowledged by the other side yet. We track this
68 // because we may need to retransmit.
70 int64 position
; // Offset of this block in the stream.
71 int64 length
; // Number of bytes in this block.
72 int64 transmissions
; // Count of transmissions of this block.
73 int64 last_message_id
; // ID of last message sending this block.
74 base::TimeTicks last_sent_time
; // Time of last message sending this block.
75 scoped_refptr
<IOBufferWithSize
> data
;
78 typedef std::vector
<Block
> BlockList
;
80 // Finds a block by position and returns it index within |list_|.
81 int FindBlock(int64 position
) const;
83 // Debugging: Writes the entire blocklist to the log.
84 void LogBlockList() const;
86 int64 current_message_id_
; // The current message id.
87 int64 send_sequence_number_
; // The sending sequence number.
90 DISALLOW_COPY_AND_ASSIGN(SentBlockList
);
95 #endif // NET_CURVECP_SENT_BLOCK_LIST_H_