summaryrefslogtreecommitdiff
path: root/chromium/net/tools/quic/quic_server.h
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/net/tools/quic/quic_server.h')
-rw-r--r--chromium/net/tools/quic/quic_server.h115
1 files changed, 115 insertions, 0 deletions
diff --git a/chromium/net/tools/quic/quic_server.h b/chromium/net/tools/quic/quic_server.h
new file mode 100644
index 00000000000..142d1d1572c
--- /dev/null
+++ b/chromium/net/tools/quic/quic_server.h
@@ -0,0 +1,115 @@
+// Copyright (c) 2012 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.
+//
+// A toy server, which listens on a specified address for QUIC traffic and
+// handles incoming responses.
+
+#ifndef NET_TOOLS_QUIC_QUIC_SERVER_H_
+#define NET_TOOLS_QUIC_QUIC_SERVER_H_
+
+#include "base/memory/scoped_ptr.h"
+#include "net/base/ip_endpoint.h"
+#include "net/quic/crypto/crypto_server_config.h"
+#include "net/quic/quic_config.h"
+#include "net/quic/quic_framer.h"
+#include "net/tools/flip_server/epoll_server.h"
+#include "net/tools/quic/quic_dispatcher.h"
+
+namespace net {
+
+class QuicCryptoServerConfig;
+
+namespace tools {
+
+class QuicDispatcher;
+
+class QuicServer : public EpollCallbackInterface {
+ public:
+ QuicServer();
+ explicit QuicServer(const QuicConfig& config);
+
+ virtual ~QuicServer();
+
+ // Start listening on the specified address.
+ bool Listen(const IPEndPoint& address);
+
+ // Wait up to 50ms, and handle any events which occur.
+ void WaitForEvents();
+
+ // Server deletion is imminent. Start cleaning up the epoll server.
+ void Shutdown();
+
+ // From EpollCallbackInterface
+ virtual void OnRegistration(
+ EpollServer* eps, int fd, int event_mask) OVERRIDE {}
+ virtual void OnModification(int fd, int event_mask) OVERRIDE {}
+ virtual void OnEvent(int fd, EpollEvent* event) OVERRIDE;
+ virtual void OnUnregistration(int fd, bool replaced) OVERRIDE {}
+
+ // Reads a packet from the given fd, and then passes it off to
+ // the QuicDispatcher. Returns true if a packet is read, false
+ // otherwise.
+ // If packets_dropped is non-null, the socket is configured to track
+ // dropped packets, and some packets are read, it will be set to the number of
+ // dropped packets.
+ static bool ReadAndDispatchSinglePacket(int fd, int port,
+ QuicDispatcher* dispatcher,
+ int* packets_dropped);
+
+ virtual void OnShutdown(EpollServer* eps, int fd) OVERRIDE {}
+
+ // Dispatches the given packet only if it looks like a valid QUIC packet.
+ // TODO(rjshade): Return a status describing why a packet was dropped, and log
+ // somehow. Maybe expose as a varz.
+ static void MaybeDispatchPacket(QuicDispatcher* dispatcher,
+ const QuicEncryptedPacket& packet,
+ const IPEndPoint& server_address,
+ const IPEndPoint& client_address);
+
+ bool overflow_supported() { return overflow_supported_; }
+
+ int packets_dropped() { return packets_dropped_; }
+
+ int port() { return port_; }
+
+ private:
+ // Initialize the internal state of the server.
+ void Initialize();
+
+ // Accepts data from the framer and demuxes clients to sessions.
+ scoped_ptr<QuicDispatcher> dispatcher_;
+ // Frames incoming packets and hands them to the dispatcher.
+ EpollServer epoll_server_;
+
+ // The port the server is listening on.
+ int port_;
+
+ // Listening connection. Also used for outbound client communication.
+ int fd_;
+
+ // If overflow_supported_ is true this will be the number of packets dropped
+ // during the lifetime of the server. This may overflow if enough packets
+ // are dropped.
+ int packets_dropped_;
+
+ // True if the kernel supports SO_RXQ_OVFL, the number of packets dropped
+ // because the socket would otherwise overflow.
+ bool overflow_supported_;
+
+ // If true, use recvmmsg for reading.
+ bool use_recvmmsg_;
+
+ // config_ contains non-crypto parameters that are negotiated in the crypto
+ // handshake.
+ QuicConfig config_;
+ // crypto_config_ contains crypto parameters for the handshake.
+ QuicCryptoServerConfig crypto_config_;
+
+ DISALLOW_COPY_AND_ASSIGN(QuicServer);
+};
+
+} // namespace tools
+} // namespace net
+
+#endif // NET_TOOLS_QUIC_QUIC_SERVER_H_