bool SOSTransportMessageSendMessageIfNeeded(SOSTransportMessageRef transport, CFStringRef circle_id, CFStringRef peer_id, CFErrorRef *error) { SOSEnginePeerMessageSentBlock sent = NULL; CFDataRef message_to_send = NULL; bool ok = false; SOSPeerRef peer = SOSPeerCreateWithEngine(SOSTransportMessageGetEngine(transport), peer_id); CFDataRef coderData = SOSEngineGetCoderData(SOSTransportMessageGetEngine(transport), peer_id); require(coderData, fail); SOSCoderRef coder = SOSCoderCreateFromData(coderData, error); require(coder, fail); SOSPeerSetCoder(peer, coder); ok = SOSPeerCoderSendMessageIfNeeded(peer, &message_to_send, circle_id, peer_id, &sent, error); coder = SOSPeerGetCoder(peer); if (message_to_send) { CFDictionaryRef peer_dict = CFDictionaryCreateForCFTypes(kCFAllocatorDefault, peer_id, message_to_send, NULL); CFDictionaryRef circle_peers = CFDictionaryCreateForCFTypes(kCFAllocatorDefault, circle_id, peer_dict, NULL); ok = ok && SOSTransportMessageSendMessages(transport, circle_peers, error); SOSPeerCoderConsume(&sent, ok); CFReleaseSafe(peer_dict); CFReleaseSafe(circle_peers); } Block_release(sent); CFReleaseSafe(message_to_send); coderData = SOSCoderCopyDER(coder, error); if(!SOSEngineSetCoderData(SOSTransportMessageGetEngine(transport), peer_id, coderData, error)){ secerror("SOSTransportMessageSendMessageIfNeeded, Could not save peer state"); } CFReleaseNull(coderData); if (coder) SOSCoderDispose(coder); fail: CFReleaseNull(peer); return ok; }
bool SOSTransportMessageHandlePeerMessage(SOSTransportMessageRef transport, CFStringRef peer_id, CFDataRef codedMessage, CFErrorRef *error){ CFDataRef decodedMessage = NULL; bool result = false; SOSPeerRef peer = SOSPeerCreateWithEngine(SOSTransportMessageGetEngine(transport), peer_id); enum SOSCoderUnwrapStatus uwstatus = SOSPeerHandleCoderMessage(peer, peer_id, codedMessage, &decodedMessage, error); if (uwstatus == SOSCoderUnwrapDecoded) { result = SOSEngineHandleMessage(SOSTransportMessageGetEngine(transport), peer_id, decodedMessage, error); } else { result = uwstatus != SOSCoderUnwrapError; } CFReleaseNull(decodedMessage); CFReleaseNull(peer); return result; }
static void SOSAccountConsiderLoggingEngineState(SOSAccountTransactionRef txn) { static int engineLogCountDown = 0; if(engineLogCountDown <= 0) { SOSEngineRef engine = SOSTransportMessageGetEngine(txn->account->kvs_message_transport); SOSEngineLogState(engine); engineLogCountDown = LOG_ENGINE_STATE_INTERVAL; } else { engineLogCountDown--; } }