//-----------------------------------------------------------------------------
// Function:    DisplayEndpointInformation
// Purpose:     Routine to display the objects and applications from an endpoint
// Parameters:  None.
//
void DisplayEndpointInformation()
{
    HRESULT hr = S_OK;
    PEER_CONTACT  *pContacts = NULL;
    PEER_ENDPOINT *pEndpoint = NULL;

    //Note:  The pContacts and pEndpoint structures
    //returned by this function have been allocated by the,
    //sample application directly using malloc, not via the p2p library.
    //We must free them by calling free.  Do not called PeerFreeData
    hr = SelectEndpoint(&pContacts, &pEndpoint);

    if (FAILED(hr))
    {
        goto exit;
    }

    DisplayEndpointObjects(pEndpoint);
    DisplayEndpointApplications(pEndpoint);


exit:
    //Releases memory used by the P2P library to cache information regarding this endpoint
    if (pEndpoint)
    {
        DeleteEndpointData(pEndpoint);
    }

    SAFE_FREE(pContacts);
    SAFE_FREE(pEndpoint);

    return;
}
예제 #2
0
// Go to the Status stage of a successful control transfer
STATIC
VOID
StatusAcknowledge (
  IN UINT8 Endpoint
)
{
  SelectEndpoint (Endpoint);
  WRITE_REG32 (ISP1761_CTRL_FUNCTION, ISP1761_CTRL_FUNCTION_STATUS);
}
예제 #3
0
// Enable going to the Data stage of a control transfer
STATIC
VOID
DataStageEnable (
  IN UINT8 Endpoint
  )
{
  SelectEndpoint (Endpoint);
  WRITE_REG32 (ISP1761_CTRL_FUNCTION, ISP1761_CTRL_FUNCTION_DSEN);
}
예제 #4
0
    void ForwardPacketToAllPeers( const char *data, int size )
    {
        std::time_t currentTime = std::time(0);
        
        for( std::vector<Peer>::iterator i = peers_.begin(); i != peers_.end(); ++i ){

            PeerEndpoint *peerEndpointToUse = SelectEndpoint( *i );
            if( peerEndpointToUse ){
                externalSocket_.SendTo( peerEndpointToUse->endpointName, data, size );
                ++peerEndpointToUse->forwardedPacketsCount;
                peerEndpointToUse->lastPacketForwardTime = currentTime;
            }
        }       
    }
예제 #5
0
// Read the FIFO for the endpoint indexed by Endpoint, into the buffer pointed
// at by Buffer, whose size is *Size bytes.
//
// If *Size is less than the number of bytes in the FIFO, return EFI_BUFFER_TOO_SMALL
//
// Update *Size with the number of bytes of data in the FIFO.
STATIC
EFI_STATUS
ReadEndpointBuffer (
  IN      UINT8   Endpoint,
  IN OUT  UINTN  *Size,
  IN OUT  VOID   *Buffer
  )
{
  UINT16  NumBytesAvailable;
  UINT32  Val32;
  UINTN   Index;
  UINTN   NumBytesRead;

  SelectEndpoint (Endpoint);

  NumBytesAvailable = READ_REG16 (ISP1761_BUFFER_LENGTH);

  if (NumBytesAvailable > *Size) {
    *Size = NumBytesAvailable;
    return EFI_BUFFER_TOO_SMALL;
  }
  *Size = NumBytesAvailable;

  /* -- NB! --
    The datasheet says the Data Port is 16 bits but it actually appears to
    be 32 bits.
   */

  // Read 32-bit chunks
  for (Index = 0; Index < NumBytesAvailable / 4; Index++) {
    ((UINT32 *) Buffer)[Index] = READ_REG32 (ISP1761_DATA_PORT);
  }

  // Read remaining bytes

  // Round NumBytesAvailable down to nearest power of 4
  NumBytesRead = NumBytesAvailable & (~0x3);
  if (NumBytesRead != NumBytesAvailable) {
    Val32 = READ_REG32 (ISP1761_DATA_PORT);
    // Copy each required byte of 32-bit word into buffer
    for (Index = 0; Index < NumBytesAvailable % 4; Index++) {
      ((UINT8 *) Buffer)[NumBytesRead + Index] = Val32 >> (Index * 8);
    }
  }
예제 #6
0
    void PollPeerPingTimer( Peer& peer, std::time_t currentTime, bool executeNowIgnoringTimeouts=false )
    {
        bool noPingsReceivedYet =
                !peer.privateEndpoint.pingReceived
                && !peer.publicEndpoint.pingReceived
                && !peer.pingEndpoint.pingReceived;

        if( !noPingsReceivedYet ){
            // check whether we should attempt to re-establish the link
            // due to no traffic arriving for PEER_ESTABLISHMENT_RETRY_TIME_SECONDS

            std::time_t mostRecentPingTime = 0;
            if( peer.privateEndpoint.pingReceived )
                mostRecentPingTime = std::max( mostRecentPingTime, peer.privateEndpoint.lastPingReceiveTime );
            if( peer.publicEndpoint.pingReceived )
                mostRecentPingTime = std::max( mostRecentPingTime, peer.publicEndpoint.lastPingReceiveTime );
            if( peer.pingEndpoint.pingReceived )
                mostRecentPingTime = std::max( mostRecentPingTime, peer.pingEndpoint.lastPingReceiveTime );
            
            if( (int)std::difftime(currentTime, mostRecentPingTime) > PEER_ESTABLISHMENT_RETRY_TIME_SECONDS ){

                peer.pingPeriodCount = 0;
                executeNowIgnoringTimeouts = true;
            }
        }


        bool inEstablishmentPhase =
                ( ( peer.pingPeriodCount < ESTABLISHMENT_PING_PERIOD_COUNT )
                &&  ( !peer.privateEndpoint.pingReceived ) )
                || noPingsReceivedYet;

        if( inEstablishmentPhase ){
            int pingPeriod;
            if( peer.pingPeriodCount < ESTABLISHMENT_PING_PERIOD_COUNT ){
            
                pingPeriod = (int) (IDLE_PING_PERIOD_SECONDS *
                        ((double)(peer.pingPeriodCount + 1) / (double) ESTABLISHMENT_PING_PERIOD_COUNT));

            }else{
                pingPeriod = IDLE_PING_PERIOD_SECONDS;
            }

            if( currentTime >= (peer.lastPingPeriodTime + pingPeriod)
                    || executeNowIgnoringTimeouts ){
                SendPing( peer.privateEndpoint, currentTime );
                SendPing( peer.publicEndpoint, currentTime );
                if( peer.pingEndpoint.pingReceived )
                    SendPing( peer.pingEndpoint, currentTime );

                peer.lastPingPeriodTime = currentTime;
                ++peer.pingPeriodCount;
            }
        
        }else{

            PeerEndpoint *peerEndpointToUse = SelectEndpoint( peer );
            assert( peerEndpointToUse != 0 );

            bool sendPing = false;

            if( executeNowIgnoringTimeouts ){

                sendPing = true;

            }else{
            
                if( peerEndpointToUse->sentPingsCount == 0 ){

                    sendPing = true;

                }else{

                    int secondsSinceLastPing = (int)std::difftime(currentTime, peerEndpointToUse->lastPingSendTime);

                    if( peerEndpointToUse->forwardedPacketsCount == 0 ){

                        if( secondsSinceLastPing >= IDLE_PING_PERIOD_SECONDS ){
                        
                            sendPing = true;
                        }

                    }else{

                        int secondsSinceLastForwardedTraffic =
                                (int)std::difftime(currentTime, peerEndpointToUse->lastPacketForwardTime);

                        if( secondsSinceLastForwardedTraffic >= IDLE_PING_PERIOD_SECONDS ){

                            if( secondsSinceLastPing >= IDLE_PING_PERIOD_SECONDS ){
                                sendPing = true;
                            }

                        }else if( secondsSinceLastPing >= ACTIVE_PING_PERIOD_SECONDS ){
                            sendPing = true;
                        }
                    }
                }
            }

            if( sendPing ){
                SendPing( *peerEndpointToUse, currentTime );
                peer.lastPingPeriodTime = currentTime;
                ++peer.pingPeriodCount;
            }
        }
    }