/// <summary> /// Callback used by VS Connect to report log messages to this application. /// </summary> /// <param name="logLevel"></param> /// <param name="vscNode"></param> /// <param name="vscLink"></param> /// <param name="vscContract"></param> /// <param name="format"></param> /// <param name="argptr"></param> /// <returns></returns> protected unsafe int _VscLogCallback(VscLogLevel logLevel , VscNode vscNode , VscLink vscLink , VscContract vscContract , string format , IntPtr argptr) { string logMessage = $"VS Connect "; logMessage += logLevel == VscLogLevel.ERROR ? "ERROR" : (logLevel == VscLogLevel.WARNING ? "WARNING" : ""); logMessage += string.Format("N:{0:x} L:{1:x} C:{2:x}", vscNode.ptr.ToInt64(), vscLink.ptr.ToInt64(), vscContract.ptr.ToInt64()); int BUFF_SIZE = 1024; byte[] tempBuff = new byte[BUFF_SIZE]; int charsOutput2 = vsprintf(tempBuff, format, argptr); //check(charsOutput2 > 0 ); logMessage += System.Text.Encoding.UTF8.GetString(tempBuff, 0, charsOutput2); if (VscLogLevel.ERROR == logLevel) { LogError(logMessage); } else if (VscLogLevel.WARNING == logLevel) { LogWarning(logMessage); } else { Log(logMessage); } return(logMessage.Length); }
public VsConnectNode(VscNode setNode) { mVsConnectNode = setNode; }
void PingCallback(VscNode vscNode, VscLink link) { /* Note that Ping Statistics include system times from both the Requester * (us) and the Responder (our peer). When both peers are running on the same * system and within the same session, they MIGHT both use a common reference * clock, and therefore the "system time" of the two peers can be directly * compared with one another. HOWEVER, this is not guaranteed on on all * operating systems, or even on different versions of the same operating * system. * * To be safe, you should always assume that the system clocks of two peers do * not refer to the same underlying reference clock, and can therefore NOT be * compared with one another. */ /// Peer's system time when VS Connect received our Ping request. double peerReceiveTime = vsc_Api_V3_t.Link_PingGetStat(link , PingMilestone.RESPONDER_REQUEST_RECEIVED , TimeMomentAttr.SYSTEM_TIME); /// Peer's system time when it processed our request inside of its /// Node_Service() call. double peerProcessTime = vsc_Api_V3_t.Link_PingGetStat(link , PingMilestone.RESPONDER_REQUEST_PROCESSED , TimeMomentAttr.SYSTEM_TIME); /// Peer's system time when it queued the Ping reponse. This happens during /// the the next call to Node_Service() after the Ping request is processed. double peerResponseTime = vsc_Api_V3_t.Link_PingGetStat(link , PingMilestone.RESPONDER_RESPONSE_QUEUED , TimeMomentAttr.SYSTEM_TIME); /// The deduced period at which the Peer is calling Node_Service(). double peerApparentSericePeriod = peerResponseTime - peerProcessTime; /// The time it took for the peer to process and respond to our request. double peerTotalProcessingTime = peerResponseTime - peerReceiveTime; /// The time that VS Connect queued our initial request for transmission. double ourRequestTransmitTime = vsc_Api_V3_t.Link_PingGetStat(link , PingMilestone.REQUESTER_REQUEST_QUEUED , TimeMomentAttr.SYSTEM_TIME); /// The time that VS Connect receved the peer's response. double ourResponseReceiveTime = vsc_Api_V3_t.Link_PingGetStat(link , PingMilestone.REQUESTER_RESPONSE_RECEIVED , TimeMomentAttr.SYSTEM_TIME); /// Time between when we sent the request and when we received the response. double totalRoundTripTime = ourResponseReceiveTime - ourRequestTransmitTime; /** This value will vary dramatically in this example due to the slow * service frequency of both peers. The higher the service frequency of the * peers, the lower and more stable this value will be, and the closer it will * be to the actual network transport latency. */ double apparentTotalRoundNetworkLatency = totalRoundTripTime - peerTotalProcessingTime; // We set manual ping's appData to 1 so we can tell the difference between // automatic/periodic ping requests and those that we initiated manually. bool isManualPing = (vsc_Api_V3_t.Link_PingGetAppData(link).ToInt64() == 1); /* * printf( "\nPing Results%s: Peer update period: %g" * "\tRound-trip communication time: %g" * , isManualPing? " (manual)" : " (automatic)" * , peerApparentSericePeriod * , apparentTotalRoundNetworkLatency ); */ }