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/client_packetizer.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/client_packetizer.h')
-rw-r--r-- | net/curvecp/client_packetizer.h | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/net/curvecp/client_packetizer.h b/net/curvecp/client_packetizer.h new file mode 100644 index 0000000..b5ca5dd --- /dev/null +++ b/net/curvecp/client_packetizer.h @@ -0,0 +1,102 @@ +// 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_CLIENT_PACKETIZER_H_ +#define NET_CURVECP_CLIENT_PACKETIZER_H_ +#pragma once + +#include "base/scoped_ptr.h" +#include "base/task.h" +#include "net/base/address_list.h" +#include "net/base/completion_callback.h" +#include "net/curvecp/packetizer.h" +#include "net/curvecp/protocol.h" + +namespace net { + +class AddressList; +class IOBuffer; +class IPEndPoint; +class UDPClientSocket; + +class ClientPacketizer : public Packetizer { + public: + ClientPacketizer(); + virtual ~ClientPacketizer(); + + int Connect(const AddressList& server, + Packetizer::Listener* listener, + CompletionCallback* callback); + + // Packetizer methods + virtual int SendMessage(ConnectionKey key, + const char* data, + size_t length, + CompletionCallback* callback); + virtual void Close(ConnectionKey key); + virtual int GetPeerAddress(IPEndPoint* endpoint) const; + virtual int max_message_payload() const; + + private: + enum StateType { + NONE, // The initial state, before connect. + LOOKUP_COOKIE, // Looking up a cookie in the disk cache. + LOOKUP_COOKIE_COMPLETE, // The disk cache lookup is complete. + SENDING_HELLO, // Sending a Hello packet. + SENDING_HELLO_COMPLETE, // Hello packet has been sent. + WAITING_COOKIE, // Waiting for a Cookie packet. + WAITING_COOKIE_COMPLETE, // The Cookie packet has arrived. + CONNECTED, // Connected + }; + + int DoLoop(int result); + int DoLookupCookie(); + int DoLookupCookieComplete(int result); + int DoSendingHello(); + int DoSendingHelloComplete(int result); + int DoWaitingCookie(); + int DoWaitingCookieComplete(int result); + int DoConnected(int result); + + void DoCallback(int result); + + // Connect to the next address in our list. + int ConnectNextAddress(); + + // We set a timeout for responses to the Hello message. + void StartHelloTimer(int milliseconds); + void RevokeHelloTimer(); + void OnHelloTimeout(); // Called when the Hello Timer fires. + + // Process the result of a Read operation. + void ProcessRead(int bytes_read); + + // Read packets until an error occurs. + int ReadPackets(); + + // Callback when an internal IO is completed. + void OnIOComplete(int result); + + StateType next_state_; + scoped_ptr<UDPClientSocket> socket_; + Packetizer::Listener* listener_; + CompletionCallback* user_callback_; + AddressList addresses_; + const struct addrinfo* current_address_; + int hello_attempts_; // Number of attempts to send a Hello Packet. + bool initiate_sent_; // Indicates whether the Initialte Packet was sent. + + scoped_refptr<IOBuffer> read_buffer_; // Buffer for interal reads. + + uchar shortterm_public_key_[32]; + + CompletionCallbackImpl<ClientPacketizer> io_callback_; + ScopedRunnableMethodFactory<ClientPacketizer> timers_factory_; + + DISALLOW_COPY_AND_ASSIGN(ClientPacketizer); +}; + +} // namespace net + +#endif // NET_CURVECP_CLIENT_PACKETIZER_H_ |