LogCabin
Protocol/Common.h
Go to the documentation of this file.
00001 /* Copyright (c) 2012 Stanford University
00002  *
00003  * Permission to use, copy, modify, and distribute this software for any
00004  * purpose with or without fee is hereby granted, provided that the above
00005  * copyright notice and this permission notice appear in all copies.
00006  *
00007  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
00008  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00009  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
00010  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00011  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00012  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00013  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00014  */
00015 
00016 /**
00017  * \file
00018  * This file contains declarations useful to all LogCabin RPCs.
00019  */
00020 
00021 #ifndef LOGCABIN_PROTOCOL_COMMON_H
00022 #define LOGCABIN_PROTOCOL_COMMON_H
00023 
00024 #include <cstdint>
00025 
00026 namespace LogCabin {
00027 namespace Protocol {
00028 namespace Common {
00029 
00030 /**
00031  * The default TCP port on which LogCabin servers serve RPCs.
00032  * TCP port 5254 is reserved by IANA for LogCabin as of April 2015.
00033  */
00034 enum { DEFAULT_PORT = 5254 };
00035 
00036 /**
00037  * Reserved MessageSocket::MessageID values.
00038  * No application-level RPCs will ever be assigned these IDs.
00039  */
00040 enum {
00041     /**
00042      * Messages that are used to check the server's liveness.
00043      */
00044     PING_MESSAGE_ID = ~0UL,
00045     /**
00046      * Messages used to check which versions of the MessageSocket framing
00047      * protocol the server supports.
00048      */
00049     VERSION_MESSAGE_ID = ~0UL - 1,
00050 };
00051 
00052 /**
00053  * Defines request and response types for messages sent using ID VERSION_MESSAGE_ID,
00054  * used to check which versions of the MessageSocket framing protocol the
00055  * server supports.
00056  */
00057 namespace VersionMessage {
00058 struct Request {
00059     // empty
00060 } __attribute__((packed));
00061 
00062 struct Response {
00063     /**
00064      * The largest version of the MessageSocket framing protocol that the
00065      * server understands. Requests with larger versions will cause the server
00066      * to close the connection. Big endian.
00067      */
00068     uint16_t maxVersionSupported;
00069 } __attribute__((packed));
00070 
00071 } // namespace VersionMessage
00072 
00073 /**
00074  * The maximum number of bytes per RPC request or response, including these
00075  * headers. This is set to slightly over 1 MB because the maximum size of log
00076  * entries is 1 MB.
00077  */
00078 enum { MAX_MESSAGE_LENGTH = 1024 + 1024 * 1024 };
00079 
00080 // This is not an enum class because it is usually used as a uint16_t;
00081 // enum class is too strict about conversions.
00082 namespace ServiceId {
00083 enum {
00084 
00085     /**
00086      * The service that LogCabin client applications communicate with via the
00087      * client library.
00088      */
00089     CLIENT_SERVICE = 1,
00090 
00091     /**
00092      * The service that LogCabin servers use to communicate with each other.
00093      * The consensus protocol runs over this service.
00094      */
00095     RAFT_SERVICE = 2,
00096 
00097     /**
00098      * Used by the logcabinctl client to query and change the internal state of
00099      * a server.
00100      */
00101     CONTROL_SERVICE = 3,
00102 };
00103 }
00104 
00105 } // namespace LogCabin::Protocol::Common
00106 } // namespace LogCabin::Protocol
00107 } // namespace LogCabin
00108 
00109 #endif // LOGCABIN_PROTOCOL_COMMON_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines