diff options
author | mbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-17 20:20:11 +0000 |
---|---|---|
committer | mbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-17 20:20:11 +0000 |
commit | 4ba51e2ab55061b8750c904c2aeca19899ac02ee (patch) | |
tree | 189758309a3f0da6fbc22ecf506ead3d216f7aed /net/curvecp/messenger.h | |
parent | e941a283e5b107f0c0a3595d0b6e11d7259d833f (diff) | |
download | chromium_src-4ba51e2ab55061b8750c904c2aeca19899ac02ee.zip chromium_src-4ba51e2ab55061b8750c904c2aeca19899ac02ee.tar.gz chromium_src-4ba51e2ab55061b8750c904c2aeca19899ac02ee.tar.bz2 |
An initial curvecp implementation. This code is not complete, but does
have a basic unittest. Crypto code is not yet implemented.
Landing so that we can collaborate on this more.
BUG=none
TEST=curvecp_unittests
Review URL: http://codereview.chromium.org/7039014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85667 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/curvecp/messenger.h')
-rw-r--r-- | net/curvecp/messenger.h | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/net/curvecp/messenger.h b/net/curvecp/messenger.h new file mode 100644 index 0000000..7bd1bb8 --- /dev/null +++ b/net/curvecp/messenger.h @@ -0,0 +1,104 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_CURVECP_MESSENGER_H_ +#define NET_CURVECP_MESSENGER_H_ +#pragma once + +#include <deque> +#include <list> + +#include "base/basictypes.h" +#include "base/task.h" +#include "base/threading/non_thread_safe.h" +#include "base/timer.h" +#include "net/base/completion_callback.h" +#include "net/curvecp/circular_buffer.h" +#include "net/curvecp/packetizer.h" +#include "net/curvecp/received_block_list.h" +#include "net/curvecp/rtt_and_send_rate_calculator.h" +#include "net/curvecp/sent_block_list.h" +#include "net/socket/socket.h" + +namespace net { + +class DrainableIOBuffer; +class IOBufferWithSize; +class Packetizer; + +// The messenger provides the reliable CurveCP transport. +class Messenger : public base::NonThreadSafe, + public Packetizer::Listener { + public: + explicit Messenger(Packetizer* packetizer); + virtual ~Messenger(); + + int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback); + int Write(IOBuffer* buf, int buf_len, CompletionCallback* callback); + + // Packetizer::Listener methods: + virtual void OnConnection(ConnectionKey key); + virtual void OnClose(Packetizer* packetizer, ConnectionKey key); + virtual void OnMessage(Packetizer* packetizer, + ConnectionKey key, + unsigned char* msg, + size_t length); + + protected: + ConnectionKey key_; + + private: + // Handle reading data from the read queue. + int InternalRead(IOBuffer* buffer, int buffer_length); + + // Extracts data from send queue to create a new buffer of data to send. + IOBufferWithSize* CreateBufferFromSendQueue(); + + // Continuation function after a SendMessage() call was blocked. + void OnSendMessageComplete(int result); + + // Protocol handling routines + void OnTimeout(); + void OnSendTimer(); + void SendMessage(int64 position); + void RecvMessage(); + void SendAck(uint32 last_message_received); + + RttAndSendRateCalculator rtt_; + Packetizer* packetizer_; + + // The send_buffer is a list of pending data to pack into messages and send + // to the remote. + CircularBuffer send_buffer_; + CompletionCallback* send_complete_callback_; + scoped_refptr<IOBuffer> pending_send_; + int pending_send_length_; + + // The read_buffer is a list of pending data which has been unpacked from + // messages and is awaiting delivery to the application. + CompletionCallback* receive_complete_callback_; + scoped_refptr<IOBuffer> pending_receive_; + int pending_receive_length_; + + // The list of received but unprocessed messages. + std::list<scoped_refptr<IOBufferWithSize> > read_queue_; + + ReceivedBlockList received_list_; + SentBlockList sent_list_; + bool send_message_in_progress_; + + // A timer to fire when a timeout has occurred. + base::OneShotTimer<Messenger> send_timeout_timer_; + // A timer to fire when we can send data. + base::OneShotTimer<Messenger> send_timer_; + + CompletionCallbackImpl<Messenger> send_message_callback_; + + ScopedRunnableMethodFactory<Messenger> factory_; + DISALLOW_COPY_AND_ASSIGN(Messenger); +}; + +} // namespace net + +#endif // NET_CURVECP_MESSENGER_H_ |