Dobby  3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
MulticastSocketsPlugin.h
1 /*
2 * If not stated otherwise in this file or this component's LICENSE file the
3 * following copyright and licenses apply:
4 *
5 * Copyright 2021 Sky UK
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19 
20 #ifndef MULTICASTSOCKETSPLUGIN_H
21 #define MULTICASTSOCKETSPLUGIN_H
22 
23 
24 #include <IDobbyPlugin.h>
25 #include <PluginBase.h>
26 
27 #include <netinet/in.h>
28 
29 #include <vector>
30 #include <string>
31 #include <memory>
32 
33 
34 // -----------------------------------------------------------------------------
44 class MulticastSocketPlugin final : public PluginBase
45 {
46 public:
47  MulticastSocketPlugin(const std::shared_ptr<IDobbyEnv>& env,
48  const std::shared_ptr<IDobbyUtils>& utils);
49  ~MulticastSocketPlugin() final;
50 
51 public:
52  std::string name() const final;
53  unsigned hookHints() const final;
54 
55 public:
56  bool postConstruction(const ContainerId& id,
57  const std::shared_ptr<IDobbyStartState>& startupState,
58  const std::string& rootfsPath,
59  const Json::Value& jsonData) final;
60 
61 private:
63  {
64  std::string name;
65  in_addr_t ipAddress;
66  in_port_t portNumber;
67  };
68 
69  std::vector<MulticastSocket> parseServerSocketsArray(const Json::Value& jsonData) const;
70  std::vector<std::string> parseClientSocketsArray(const Json::Value& jsonData) const;
71 
72  int createServerSocket(in_addr_t ip, in_port_t port);
73  int createClientSocket();
74 
75 private:
76  const std::string mName;
77  const std::shared_ptr<IDobbyUtils> mUtilities;
78 };
79 
80 #endif // MULTICASTSOCKETSPLUGIN_H
A wrapper around a std::string, used to add some type definition to to an id and also to sanity check...
Definition: ContainerId.h:41
Plugin used to setup multicast server and client sockets out of the container and passes their file d...
Definition: MulticastSocketsPlugin.h:45
int createClientSocket()
Creates client udp socket.
Definition: MulticastSocketsPlugin.cpp:331
unsigned hookHints() const final
Indiciates which hook points we want and whether to run the asynchronously or synchronously with the ...
Definition: MulticastSocketsPlugin.cpp:66
std::vector< MulticastSocket > parseServerSocketsArray(const Json::Value &jsonData) const
Parses and verifies server socket data from json array.
Definition: MulticastSocketsPlugin.cpp:166
std::string name() const final
Boilerplate that just returns the name of the hook.
Definition: MulticastSocketsPlugin.cpp:54
int createServerSocket(in_addr_t ip, in_port_t port)
Creates socket and binds it to multicast ip and port.
Definition: MulticastSocketsPlugin.cpp:273
bool postConstruction(const ContainerId &id, const std::shared_ptr< IDobbyStartState > &startupState, const std::string &rootfsPath, const Json::Value &jsonData) final
Creates multicast server and client sockets out of the container and passes their file descriptors to...
Definition: MulticastSocketsPlugin.cpp:98
std::vector< std::string > parseClientSocketsArray(const Json::Value &jsonData) const
Parses and verifies client socket data from json array.
Definition: MulticastSocketsPlugin.cpp:234
Basic object that provides the default overrides for a plugin.
Definition: PluginBase.h:38
Definition: MulticastSocketsPlugin.h:63