* Route the provided message to its corresponding handler (if any). * * This will first verify the timestamp of that RPC message (if any) and subsequently, rejects any message whose * timestamp is less than the remote log position of the client Endpoint; otherwise, the endpoint's remote log * position is updated to that timestamp. It is not expected to happen, but any message lacking an RPC me
| 324 | * @param message The RPC message you want to process. |
| 325 | */ |
| 326 | void JsonRpcConnection::MessageHandler(const Dictionary::Ptr& message) |
| 327 | { |
| 328 | std::shared_lock wgLock(*m_WaitGroup, std::try_to_lock); |
| 329 | if (!wgLock) { |
| 330 | return; |
| 331 | } |
| 332 | |
| 333 | if (m_Endpoint && message->Contains("ts")) { |
| 334 | double ts = message->Get("ts"); |
| 335 | |
| 336 | /* ignore old messages */ |
| 337 | if (ts < m_Endpoint->GetRemoteLogPosition()) |
| 338 | return; |
| 339 | |
| 340 | m_Endpoint->SetRemoteLogPosition(ts); |
| 341 | } |
| 342 | |
| 343 | MessageOrigin::Ptr origin = new MessageOrigin(); |
| 344 | origin->FromClient = this; |
| 345 | |
| 346 | if (m_Endpoint) { |
| 347 | if (m_Endpoint->GetZone() != Zone::GetLocalZone()) |
| 348 | origin->FromZone = m_Endpoint->GetZone(); |
| 349 | else |
| 350 | origin->FromZone = Zone::GetByName(message->Get("originZone")); |
| 351 | } |
| 352 | |
| 353 | Value vmethod; |
| 354 | |
| 355 | if (!message->Get("method", &vmethod)) { |
| 356 | Value vid; |
| 357 | |
| 358 | if (!message->Get("id", &vid)) |
| 359 | return; |
| 360 | |
| 361 | Log(LogWarning, "JsonRpcConnection", |
| 362 | "We received a JSON-RPC response message. This should never happen because we're only ever sending notifications."); |
| 363 | |
| 364 | return; |
| 365 | } |
| 366 | |
| 367 | String method = vmethod; |
| 368 | |
| 369 | Log(LogNotice, "JsonRpcConnection") |
| 370 | << "Received '" << method << "' message from identity '" << m_Identity << "'."; |
| 371 | |
| 372 | Dictionary::Ptr resultMessage = new Dictionary(); |
| 373 | |
| 374 | try { |
| 375 | ApiFunction::Ptr afunc = ApiFunction::GetByName(method); |
| 376 | |
| 377 | if (!afunc) { |
| 378 | Log(LogNotice, "JsonRpcConnection") |
| 379 | << "Call to non-existent function '" << method << "' from endpoint '" << m_Identity << "'."; |
| 380 | } else { |
| 381 | if (m_Endpoint) { |
| 382 | m_Endpoint->AddMessageReceived(afunc); |
| 383 | } |