0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Protocol.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
28 #ifndef HYPERSPACE_PROTOCOL_H
29 #define HYPERSPACE_PROTOCOL_H
30 
31 #include <set>
32 #include <vector>
33 
34 #include "AsyncComm/CommBuf.h"
35 #include "AsyncComm/Protocol.h"
36 
37 #include "HandleCallback.h"
38 #include "Notification.h"
39 #include "SessionData.h"
40 
41 namespace Hyperspace {
42 
48  struct Attribute {
49  Attribute() { }
55  Attribute(const char *n, const void *v, uint32_t vl)
56  : name(n), value(v), value_len(vl) { }
57 
59  const char *name;
60 
62  const void *value;
63 
65  uint32_t value_len;
66  };
67 
69  class Protocol : public Hypertable::Protocol {
70 
71  public:
72 
73  // client/server protocol version; using msb to avoid overlaps with
74  // Session::OpenFlags
75  static const int Version = 0xf0000002;
76 
77  virtual const char *command_text(uint64_t command);
78 
79  static CommBuf *create_client_keepalive_request(uint64_t session_id,
80  std::set<uint64_t> &delivered_events, bool destroy_session=false);
81  static CommBuf *
82  create_server_keepalive_request(uint64_t session_id, int error);
83  static CommBuf *
85  static CommBuf *
86  create_server_redirect_request(const std::string &host);
87  static CommBuf *create_handshake_request(uint64_t session_id, const std::string &name);
88  static CommBuf *
89  create_open_request(const std::string &name, uint32_t flags,
90  HandleCallbackPtr &callback, const std::vector<Attribute> &init_attrs);
91  static CommBuf *create_close_request(uint64_t handle);
92  static CommBuf *create_mkdir_request(const std::string &name, bool create_intermediate, const std::vector<Attribute> *init_attrs);
93  static CommBuf *create_delete_request(const std::string &name);
94  static CommBuf *
95  create_attr_set_request(uint64_t handle, const std::string *name, uint32_t oflags,
96  const std::string &attr, const void *value, size_t value_len);
97  static CommBuf *
98  create_attr_set_request(uint64_t handle, const std::string *name, uint32_t oflags,
99  const std::vector<Attribute> &attrs);
100  static CommBuf *
101  create_attr_incr_request(uint64_t handle, const std::string *name, const std::string &attr);
102  static CommBuf *
103  create_attr_get_request(uint64_t handle, const std::string *name, const std::string &attr);
104  static CommBuf *
105  create_attrs_get_request(uint64_t handle, const std::string *name, const std::vector<std::string> &attrs);
106 
121  static CommBuf *
122  create_attr_del_request(uint64_t handle, const std::string &name);
123 
139  static CommBuf *create_attr_exists_request(uint64_t handle,
140  const std::string &attr);
141 
158  static CommBuf *create_attr_exists_request(const std::string &name,
159  const std::string &attr);
160 
161  static CommBuf *create_attr_list_request(uint64_t handle);
162  static CommBuf *create_readdir_request(uint64_t handle);
163  static CommBuf *create_readdir_attr_request(uint64_t handle, const std::string *name,
164  const std::string &attr, bool include_sub_entries);
165  static CommBuf *create_readpath_attr_request(uint64_t handle, const std::string *name,
166  const std::string &attr);
167  static CommBuf *create_exists_request(const std::string &name);
168 
169  static CommBuf *
170  create_lock_request(uint64_t handle, uint32_t mode, bool try_lock);
171  static CommBuf *create_release_request(uint64_t handle);
172 
173  static CommBuf *
174  create_event_notification(uint64_t handle, const std::string &name,
175  const void *value, size_t value_len);
176 
177  static CommBuf *create_status_request();
179 
180  static const uint64_t COMMAND_KEEPALIVE = 0;
181  static const uint64_t COMMAND_HANDSHAKE = 1;
182  static const uint64_t COMMAND_OPEN = 2;
183  static const uint64_t COMMAND_STAT = 3;
184  static const uint64_t COMMAND_CANCEL = 4;
185  static const uint64_t COMMAND_CLOSE = 5;
186  static const uint64_t COMMAND_POISON = 6;
187  static const uint64_t COMMAND_MKDIR = 7;
188  static const uint64_t COMMAND_ATTRSET = 8;
189  static const uint64_t COMMAND_ATTRGET = 9;
190  static const uint64_t COMMAND_ATTRDEL = 10;
191  static const uint64_t COMMAND_ATTREXISTS = 11;
192  static const uint64_t COMMAND_ATTRLIST = 12;
193  static const uint64_t COMMAND_EXISTS = 13;
194  static const uint64_t COMMAND_DELETE = 14;
195  static const uint64_t COMMAND_READDIR = 15;
196  static const uint64_t COMMAND_LOCK = 16;
197  static const uint64_t COMMAND_RELEASE = 17;
198  static const uint64_t COMMAND_CHECKSEQUENCER = 18;
199  static const uint64_t COMMAND_STATUS = 19;
200  static const uint64_t COMMAND_REDIRECT = 20;
201  static const uint64_t COMMAND_READDIRATTR = 21;
202  static const uint64_t COMMAND_ATTRINCR = 22;
203  static const uint64_t COMMAND_READPATHATTR = 23;
204  static const uint64_t COMMAND_SHUTDOWN = 24;
205  static const uint64_t COMMAND_MAX = 25;
206 
207  static const char * command_strs[COMMAND_MAX];
208 
209  private:
210 
219  static uint32_t filename_to_group(const std::string &path) {
220  const char *ptr;
221  uint32_t gid = 0;
222  // add initial '/' if it's not there
223  if (path[0] != '/')
224  gid += (uint32_t)'/';
225  for (ptr=path.c_str(); *ptr; ++ptr)
226  gid += (uint32_t)*ptr;
227  // remove trailing slash
228  if (*(ptr-1) == '/')
229  gid -= (uint32_t)'/';
230  return gid;
231  }
232 
233  };
234 
236 }
237 
238 #endif // HYPERSPACE_PROTOCOL_H
static CommBuf * create_lock_request(uint64_t handle, uint32_t mode, bool try_lock)
Definition: Protocol.cc:486
static CommBuf * create_attr_exists_request(uint64_t handle, const std::string &attr)
Creates attr_exists request message.
Definition: Protocol.cc:390
static CommBuf * create_handshake_request(uint64_t session_id, const std::string &name)
Definition: Protocol.cc:149
static CommBuf * create_server_keepalive_request(uint64_t session_id, int error)
Definition: Protocol.cc:107
static const uint64_t COMMAND_HANDSHAKE
Definition: Protocol.h:181
std::shared_ptr< SessionData > SessionDataPtr
Definition: SessionData.h:156
static const uint64_t COMMAND_REDIRECT
Definition: Protocol.h:200
static CommBuf * create_readdir_request(uint64_t handle)
Definition: Protocol.cc:425
static const uint64_t COMMAND_STAT
Definition: Protocol.h:183
static CommBuf * create_attr_list_request(uint64_t handle)
Definition: Protocol.cc:417
static CommBuf * create_attr_set_request(uint64_t handle, const std::string *name, uint32_t oflags, const std::string &attr, const void *value, size_t value_len)
Definition: Protocol.cc:243
Attribute(const char *n, const void *v, uint32_t vl)
Constructor.
Definition: Protocol.h:55
Hyperspace definitions
static CommBuf * create_readdir_attr_request(uint64_t handle, const std::string *name, const std::string &attr, bool include_sub_entries)
Definition: Protocol.cc:433
static CommBuf * create_shutdown_request()
Definition: Protocol.cc:518
static CommBuf * create_close_request(uint64_t handle)
Definition: Protocol.cc:200
virtual const char * command_text(uint64_t command)=0
Returns the string representation of a command code.
const char * name
Name of extended attribute.
Definition: Protocol.h:59
static CommBuf * create_mkdir_request(const std::string &name, bool create_intermediate, const std::vector< Attribute > *init_attrs)
Definition: Protocol.cc:208
static CommBuf * create_attr_incr_request(uint64_t handle, const std::string *name, const std::string &attr)
Definition: Protocol.cc:302
static const char * command_strs[COMMAND_MAX]
Definition: Protocol.h:207
static const int Version
Definition: Protocol.h:75
static CommBuf * create_delete_request(const std::string &name)
Definition: Protocol.cc:233
static CommBuf * create_readpath_attr_request(uint64_t handle, const std::string *name, const std::string &attr)
Definition: Protocol.cc:455
static CommBuf * create_attrs_get_request(uint64_t handle, const std::string *name, const std::vector< std::string > &attrs)
Definition: Protocol.cc:349
static const uint64_t COMMAND_CHECKSEQUENCER
Definition: Protocol.h:198
std::shared_ptr< HandleCallback > HandleCallbackPtr
static CommBuf * create_attr_get_request(uint64_t handle, const std::string *name, const std::string &attr)
Definition: Protocol.cc:325
static CommBuf * create_status_request()
Definition: Protocol.cc:510
static CommBuf * create_client_keepalive_request(uint64_t session_id, std::set< uint64_t > &delivered_events, bool destroy_session=false)
Definition: Protocol.cc:89
Declarations for CommBuf.
Declarations for Protocol.
Abstract base class for server protocol drivers.
Definition: Protocol.h:49
static CommBuf * create_server_redirect_request(const std::string &host)
Definition: Protocol.cc:137
const void * value
Pointer to attribute value.
Definition: Protocol.h:62
static const uint64_t COMMAND_CANCEL
Definition: Protocol.h:184
Message buffer for holding data to be transmitted over a network.
Definition: CommBuf.h:79
Holds extended attribute and value.
Definition: Protocol.h:48
static CommBuf * create_event_notification(uint64_t handle, const std::string &name, const void *value, size_t value_len)
static CommBuf * create_release_request(uint64_t handle)
Definition: Protocol.cc:498
uint32_t value_len
Length of attribute value.
Definition: Protocol.h:65
static uint32_t filename_to_group(const std::string &path)
Generates Comm header gid for pathname.
Definition: Protocol.h:219
static CommBuf * create_exists_request(const std::string &name)
Definition: Protocol.cc:476
static const uint64_t COMMAND_POISON
Definition: Protocol.h:186
static const uint64_t COMMAND_KEEPALIVE
Definition: Protocol.h:180
static CommBuf * create_attr_del_request(uint64_t handle, const std::string &name)
Creates attr_del request message.
Definition: Protocol.cc:379
static CommBuf * create_open_request(const std::string &name, uint32_t flags, HandleCallbackPtr &callback, const std::vector< Attribute > &init_attrs)
Definition: Protocol.cc:165