MCPcopy Create free account
hub / github.com/COVESA/vsomeip / add_connection

Method add_connection

implementation/endpoints/src/local_server.cpp:183–281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

181 }
182}
183void local_server::add_connection(client_t _client, [[maybe_unused]] client_t _expected_id, std::shared_ptr<local_socket> _socket,
184 std::shared_ptr<local_receive_buffer> _buffer, uint32_t _lc_count, std::string _environment,
185 boost::asio::ip::address _routing_address, port_t _routing_port) {
186 std::unique_lock lock{mtx_};
187 if (_lc_count == lc_count_) {
188 if (_expected_id != own_client_id_ && _expected_id != VSOMEIP_CLIENT_UNSET) {
189 VSOMEIP_WARNING_P << "Connection refused due to wrong client id, expected: " << hex4(_expected_id)
190 << ", actual: " << hex4(own_client_id_) << ", from client: " << hex4(_client);
191 // This should not happen for the router, as the router for tcp needs to be configured, an no other
192 // application should be able to claim this ip+port
193 _socket->stop(true);
194 return;
195 }
196 if (auto rh = routing_host_.lock(); rh) {
197 auto const peer_endpoint = _socket->peer_endpoint();
198 // Carful: Order matters. First call lazy_load (lazy load of config for this client), before trying to create
199 // the endpoint (as the creation method is trying to reason whether the connection is allowed based on the loaded config).
200 // Carful: These calls should happen under the lock to guarantee consistency, and before the endpoint might be removed
201 // again from the map
202 rh->lazy_load(_environment);
203
204 std::stringstream ss;
205
206 if (is_router_) {
207 ss << "Assigned client ID 0x" << hex4(_client) << " to \"" << utility::get_client_name(configuration_, _client) << "\" (\""
208 << _environment << "\")";
209
210 // check if is uds socket
211 if (_socket->own_port() != VSOMEIP_SEC_PORT_UNUSED) {
212 ss << " @ " << peer_endpoint.address() << ":" << peer_endpoint.port();
213 } else {
214 vsomeip_sec_client_t sec_client{};
215 _socket->update(sec_client, *configuration_);
216 ss << " @ " << sec_client.user << "/" << sec_client.group;
217 if (!_routing_address.is_unspecified() && _routing_port != ILLEGAL_PORT) {
218 ss << " (guest: " << _routing_address.to_string() << ":" << _routing_port << ")";
219 }
220 }
221 }
222
223 auto ep = local_endpoint::create_server_ep(
224 local_endpoint_context{io_, configuration_, routing_host_},
225 local_endpoint_params{_client, rh->get_client(), std::move(_environment), std::move(_socket),
226 // For TCP sockets use the real peer endpoint directly.
227 // For UDS, fall back to what the client advertised in assign_client_command.
228 !peer_endpoint.address().is_unspecified() ? peer_endpoint.address() : _routing_address,
229 peer_endpoint.port() != 0 ? static_cast<port_t>(peer_endpoint.port()) : _routing_port},
230 std::move(_buffer));
231 if (!ep) {
232 VSOMEIP_ERROR_P << "endpoint creation failed for client: " << hex4(_client) << ", self: " << this;
233 // socket is closed already in the create_server_ep on failure
234 // clean-up id
235 utility::release_client_id(configuration_->get_network(), _client);
236 return;
237 }
238
239 if (std::find(blocked_addresses_.begin(), blocked_addresses_.end(), peer_endpoint.address()) != blocked_addresses_.end()) {
240 VSOMEIP_WARNING_P << "connection from client " << hex4(_client) << ", " << ep->name() << ", " << ep->name()

Callers 1

hand_overMethod · 0.45

Calls 15

hex4Function · 0.85
lockMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
insertMethod · 0.80
set_assignedMethod · 0.80
stopMethod · 0.45
peer_endpointMethod · 0.45
lazy_loadMethod · 0.45
own_portMethod · 0.45
updateMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected