1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
16 #ifndef CEPH_DISPATCHER_H
17 #define CEPH_DISPATCHER_H
19 #include "include/assert.h"
20 #include "include/buffer_fwd.h"
21 #include "include/assert.h"
32 explicit Dispatcher(CephContext *cct_)
36 virtual ~Dispatcher() { }
39 * The Messenger calls this function to query if you are capable
40 * of "fast dispatch"ing a message. Indicating that you can fast
41 * dispatch it requires that you:
42 * 1) Handle the Message quickly and without taking long-term contended
43 * locks. (This function is likely to be called in-line with message
45 * 2) Be able to accept the Message even if you have not yet received
46 * an ms_handle_accept() notification for the Connection it is associated
47 * with, and even if you *have* called mark_down() or received an
48 * ms_handle_reset() (or similar) call on the Connection. You will
49 * not receive more than one dead "message" (and should generally be
50 * prepared for that circumstance anyway, since the normal dispatch can begin,
51 * then trigger Connection failure before it's percolated through your system).
52 * We provide ms_handle_fast_[connect|accept] calls if you need them, under
53 * similar speed and state constraints as fast_dispatch itself.
54 * 3) Be able to make a determination on fast_dispatch without relying
55 * on particular system state -- the ms_can_fast_dispatch() call might
56 * be called multiple times on a single message; the state might change between
57 * calling ms_can_fast_dispatch and ms_fast_dispatch; etc.
59 * @param m The message we want to fast dispatch.
60 * @returns True if the message can be fast dispatched; false otherwise.
62 virtual bool ms_can_fast_dispatch(const Message *m) const { return false;}
64 * This function determines if a dispatcher is included in the
65 * list of fast-dispatch capable Dispatchers.
66 * @returns True if the Dispatcher can handle any messages via
67 * fast dispatch; false otherwise.
69 virtual bool ms_can_fast_dispatch_any() const { return false; }
71 * Perform a "fast dispatch" on a given message. See
72 * ms_can_fast_dispatch() for the requirements.
74 * @param m The Message to fast dispatch.
76 virtual void ms_fast_dispatch(Message *m) { ceph_abort(); }
78 * Let the Dispatcher preview a Message before it is dispatched. This
79 * function is called on *every* Message, prior to the fast/regular dispatch
80 * decision point, but it is only used on fast-dispatch capable systems. An
81 * implementation of ms_fast_preprocess must be essentially lock-free in the
82 * same way as the ms_fast_dispatch function is (in particular, ms_fast_preprocess
83 * may be called while the Messenger holds internal locks that prevent progress from
84 * other threads, so any locks it takes must be at the very bottom of the hierarchy).
85 * Messages are delivered in receipt order within a single Connection, but there are
86 * no guarantees across Connections. This makes it useful for some limited
87 * coordination between Messages which can be fast_dispatch'ed and those which must
88 * go through normal dispatch.
90 * @param m A message which has been received
92 virtual void ms_fast_preprocess(Message *m) {}
94 * The Messenger calls this function to deliver a single message.
96 * @param m The message being delivered. You (the Dispatcher)
97 * are given a single reference count on it.
99 virtual bool ms_dispatch(Message *m) = 0;
102 * This function will be called whenever a Connection is newly-created
103 * or reconnects in the Messenger.
105 * @param con The new Connection which has been established. You are not
106 * granted a reference to it -- take one if you need one!
108 virtual void ms_handle_connect(Connection *con) {}
111 * This function will be called synchronously whenever a Connection is
112 * newly-created or reconnects in the Messenger, if you support fast
113 * dispatch. It is guaranteed to be called before any messages are
116 * @param con The new Connection which has been established. You are not
117 * granted a reference to it -- take one if you need one!
119 virtual void ms_handle_fast_connect(Connection *con) {}
122 * Callback indicating we have accepted an incoming connection.
124 * @param con The (new or existing) Connection associated with the session
126 virtual void ms_handle_accept(Connection *con) {}
129 * Callback indicating we have accepted an incoming connection, if you
130 * support fast dispatch. It is guaranteed to be called before any messages
133 * @param con The (new or existing) Connection associated with the session
135 virtual void ms_handle_fast_accept(Connection *con) {}
138 * this indicates that the ordered+reliable delivery semantics have
139 * been violated. Messages may have been lost due to a fault
140 * in the network connection.
141 * Only called on lossy Connections.
143 * @param con The Connection which broke. You are not granted
146 virtual bool ms_handle_reset(Connection *con) = 0;
149 * This indicates that the ordered+reliable delivery semantics
150 * have been violated because the remote somehow reset.
151 * It implies that incoming messages were dropped, and
152 * probably some of our previous outgoing messages were too.
154 * @param con The Connection which broke. You are not granted
157 virtual void ms_handle_remote_reset(Connection *con) = 0;
160 * This indicates that the connection is both broken and further
161 * connection attempts are failing because other side refuses
164 * @param con The Connection which broke. You are not granted
167 virtual bool ms_handle_refused(Connection *con) = 0;
170 * @defgroup Authentication
174 * Retrieve the AuthAuthorizer for the given peer type. It might not
175 * provide one if it knows there is no AuthAuthorizer for that type.
177 * @param dest_type The peer type we want the authorizer for.
178 * @param a Double pointer to an AuthAuthorizer. The Dispatcher will fill
179 * in *a with the correct AuthAuthorizer, if it can. Make sure that you have
180 * set *a to NULL before calling in.
181 * @param force_new Force the Dispatcher to wait for a new set of keys before
182 * returning the authorizer.
184 * @return True if this function call properly filled in *a, false otherwise.
186 virtual bool ms_get_authorizer(int dest_type, AuthAuthorizer **a, bool force_new) { return false; }
188 * Verify the authorizer for a new incoming Connection.
190 * @param con The new incoming Connection
191 * @param peer_type The type of the endpoint which initiated this Connection
192 * @param protocol The ID of the protocol in use (at time of writing, cephx or none)
193 * @param authorizer The authorization string supplied by the remote
194 * @param authorizer_reply Output param: The string we should send back to
195 * the remote to authorize ourselves. Only filled in if isvalid
196 * @param isvalid Output param: True if authorizer is valid, false otherwise
198 * @return True if we were able to prove or disprove correctness of
199 * authorizer, false otherwise.
201 virtual bool ms_verify_authorizer(Connection *con,
204 ceph::bufferlist& authorizer,
205 ceph::bufferlist& authorizer_reply,
207 CryptoKey& session_key) { return false; }
209 * @} //Authentication
214 explicit Dispatcher(const Dispatcher &rhs);
215 Dispatcher& operator=(const Dispatcher &rhs);