示例#1
0
bool_t osTimerElapsed(OsTimer *timer)
{
   if(!timer->running)
      return FALSE;

   if(timeCompare(osGetTickCount(), timer->startTime + timer->interval) >= 0)
      return TRUE;
   else
      return FALSE;
}
void MovieHash::randomDoubleFeature(std::string input1, std::string input2){
    int i;
    int z=0;
    int j=0;
    bool firstPick=false;
    bool found1=false;
    bool found2=false;
    HashElem *tmp=new HashElem;
    for(int x=0; x<5;x++){
        if(hashTable[x]!=NULL){
            tmp=hashTable[x];
            while(tmp!=NULL){
                if(tmp->title==input1){
                    bool SoE=true;
                    addTime(z,tmp->startTime,tmp->endTime,SoE);
                    tmp=tmp->next;
                    z=z+2;
                    if(z==8){
                        z=0;
                    }
                    found1=true;
                }
                else if(tmp->title==input2){
                    bool SoE=false;
                    addTime(j,tmp->startTime,tmp->endTime,SoE);
                    tmp=tmp->next;
                    j=j+2;
                    if(j==8){
                        j=0;
                    }
                    found2=true;
                }
                else{
                    tmp=tmp->next;
                }
            }
        }
    }
        for(int a=0;a<5;a=a+2){
            bool compare=timeCompare(movieOne[a],movieOne[a+1],movieTwo[a],movieTwo[a+1]);
            if(compare==true){
                if(firstPick==false){
                    if(movieTwo[a]<movieOne[a]){
                        cout<<input1<<" from "<<movieTwo[a]<<"-"<<movieTwo[a+1]<<", and "<<input2<<" from "<<movieOne[a]<<"-"<<movieOne[a+1]<<endl;
                        firstPick=true;
                    }
                    else{
                        cout<<input1<<" from "<<movieOne[a]<<"-"<<movieOne[a+1]<<", and "<<input2<<" from "<<movieTwo[a]<<"-"<<movieTwo[a+1]<<endl;
                        firstPick=true;
                    }
                }
        }
      }
}
示例#3
0
Socket *tcpKillOldestConnection(void)
{
   uint_t i;
   Socket *socket;
   Socket *oldestSocket;

   //Keep track of the oldest socket in the TIME-WAIT state
   oldestSocket = NULL;

   //Loop through socket descriptors
   for(i = 0; i < SOCKET_MAX_COUNT; i++)
   {
      //Point to the current socket descriptor
      socket = &socketTable[i];

      //TCP connection found?
      if(socket->type == SOCKET_TYPE_STREAM)
      {
         //Check current state
         if(socket->state == TCP_STATE_TIME_WAIT)
         {
            //Keep track of the oldest socket in the TIME-WAIT state
            if(oldestSocket == NULL)
            {
               //Save socket handle
               oldestSocket = socket;
            }
            else if(timeCompare(socket->timeWaitTimer.startTime,
               oldestSocket->timeWaitTimer.startTime) < 0)
            {
               //Save socket handle
               oldestSocket = socket;
            }
         }
      }
   }

   //Any connection in the TIME-WAIT state?
   if(oldestSocket != NULL)
   {
      //Enter CLOSED state
      tcpChangeState(oldestSocket, TCP_STATE_CLOSED);
      //Delete TCB
      tcpDeleteControlBlock(oldestSocket);
      //Mark the socket as closed
      oldestSocket->type = SOCKET_TYPE_UNUSED;
   }

   //The oldest connection in the TIME-WAIT state can be reused
   //when the socket table runs out of space
   return oldestSocket;
}
示例#4
0
bool_t tcpTimerElapsed(TcpTimer *timer)
{
   systime_t time;

   //Check whether the timer is running
   if(!timer->running)
      return FALSE;

   //Get current time
   time = osGetSystemTime();

   //Check whether the specified time interval has elapsed
   if(timeCompare(time, timer->startTime + timer->interval) >= 0)
      return TRUE;
   else
      return FALSE;
}
示例#5
0
文件: mld.c 项目: rpc-fw/analyzer
void mldTick(NetInterface *interface)
{
   uint_t i;
   systime_t time;
   Ipv6FilterEntry *entry;

   //Get current time
   time = osGetTickCount();

   //Acquire exclusive access to the IPv6 filter table
   osMutexAcquire(interface->ipv6FilterMutex);

   //Loop through filter table entries
   for(i = 0; i < interface->ipv6FilterSize; i++)
   {
      //Point to the current entry
      entry = &interface->ipv6Filter[i];

      //Delaying Listener state?
      if(entry->state == MLD_STATE_DELAYING_LISTENER)
      {
         //Timer expired?
         if(timeCompare(time, entry->timer) >= 0)
         {
            //Send a Multicast Listener Report message
            mldSendListenerReport(interface, &entry->addr);

            //Set flag
            entry->flag = TRUE;
            //Switch to the Idle Listener state
            entry->state = MLD_STATE_IDLE_LISTENER;
         }
      }
   }

   //Release exclusive access to the IPv6 filter table
   osMutexRelease(interface->ipv6FilterMutex);
}
示例#6
0
文件: ndp.c 项目: nandojve/embedded
NdpCacheEntry *ndpCreateEntry(NetInterface *interface)
{
   uint_t i;
   NdpCacheEntry *entry;
   NdpCacheEntry *oldestEntry;

   //Keep track of the oldest entry
   oldestEntry = &interface->ndpCache[0];

   //Loop through Neighbor cache entries
   for(i = 0; i < NDP_CACHE_SIZE; i++)
   {
      //Point to the current entry
      entry = &interface->ndpCache[i];

      //Check whether the entry is currently in used or not
      if(entry->state == NDP_STATE_NONE)
      {
         //Erase contents
         memset(entry, 0, sizeof(NdpCacheEntry));
         //Return a pointer to the Neighbor cache entry
         return entry;
      }

      //Keep track of the oldest entry in the table
      if(timeCompare(entry->timestamp, oldestEntry->timestamp) < 0)
         oldestEntry = entry;
   }

   //Drop any pending packets
   ndpFlushQueuedPackets(interface, oldestEntry);
   //The oldest entry is removed whenever the table runs out of space
   memset(oldestEntry, 0, sizeof(NdpCacheEntry));
   //Return a pointer to the Neighbor cache entry
   return oldestEntry;
}
示例#7
0
DnsCacheEntry *dnsCreateEntry(void)
{
   uint_t i;
   DnsCacheEntry *entry;
   DnsCacheEntry *oldestEntry;

   //Keep track of the oldest entry
   oldestEntry = &dnsCache[0];

   //Loop through DNS cache entries
   for(i = 0; i < DNS_CACHE_SIZE; i++)
   {
      //Point to the current entry
      entry = &dnsCache[i];

      //Check whether the entry is currently in used or not
      if(entry->state == DNS_STATE_NONE)
      {
         //Erase contents
         memset(entry, 0, sizeof(DnsCacheEntry));
         //Return a pointer to the DNS entry
         return entry;
      }

      //Keep track of the oldest entry in the table
      if(timeCompare(entry->timestamp, oldestEntry->timestamp) < 0)
         oldestEntry = entry;
   }

   //The oldest entry is removed whenever the table runs out of space
   dnsDeleteEntry(oldestEntry);
   //Erase contents
   memset(oldestEntry, 0, sizeof(DnsCacheEntry));
   //Return a pointer to the DNS entry
   return oldestEntry;
}
void MovieHash::doubleFeature(std::string input1, std::string input2){
    int i;
    int z=0;
    int j=0;
    bool found1=false;
    bool found2=false;
    HashElem *tmp=new HashElem;
    for(int x=0; x<5;x++){
        if(hashTable[x]!=NULL){
            tmp=hashTable[x];
            while(tmp!=NULL){
                if(tmp->title==input1){
                    //cout<<input1<<": from "<<tmp->startTime<<" to "<<tmp->endTime<<endl;
                    bool SoE=true;
                    addTime(z,tmp->startTime,tmp->endTime,SoE);
                    tmp=tmp->next;
                    z=z+2;
                    if(z==8){
                        z=0;
                    }
                    found1=true;
                }
                else if(tmp->title==input2){
                    bool SoE=false;
                    addTime(j,tmp->startTime,tmp->endTime,SoE);
                    tmp=tmp->next;
                    j=j+2;
                    if(j==8){
                        j=0;
                    }
                    found2=true;
                }
                else{
                    tmp=tmp->next;
                }
            }
        }
    }
    if(found1==false and found2==false){
       cout<<"1 or more movies not found."<<endl;
    }
    else{
        for(int a=0;a<5;a=a+2){
            bool compare=timeCompare(movieOne[a],movieOne[a+1],movieTwo[a],movieTwo[a+1]);
            if(compare==true){
                if(movieTwo[a]<movieOne[a]){
                    cout<<input1<<" from "<<movieTwo[a]<<"-"<<movieTwo[a+1]<<", and "<<input2<<" from "<<movieOne[a]<<"-"<<movieOne[a+1]<<endl;
                }
                else{
                    cout<<input1<<" from "<<movieOne[a]<<"-"<<movieOne[a+1]<<", and "<<input2<<" from "<<movieTwo[a]<<"-"<<movieTwo[a+1]<<endl;
                }
        }
      }
    }

    /*for(int y=0;y<6;y++){
        cout<<movieOne[y]<<endl;
    }
    for(int y=0;y<6;y++){
        cout<<movieTwo[y]<<endl;
    }*/
}
error_t httpGenerateNonce(HttpServerContext *context,
   char_t *output, size_t *length)
{
#if (HTTP_SERVER_DIGEST_AUTH_SUPPORT == ENABLED)
   error_t error;
   uint_t i;
   HttpNonceCacheEntry *entry;
   HttpNonceCacheEntry *oldestEntry;
   uint8_t nonce[HTTP_SERVER_NONCE_SIZE];

   //Acquire exclusive access to the nonce cache
   osAcquireMutex(&context->nonceCacheMutex);

   //Keep track of the oldest entry
   oldestEntry = &context->nonceCache[0];

   //Loop through nonce cache entries
   for(i = 0; i < HTTP_SERVER_NONCE_CACHE_SIZE; i++)
   {
      //Point to the current entry
      entry = &context->nonceCache[i];

      //Check whether the entry is currently in used or not
      if(!entry->count)
         break;

      //Keep track of the oldest entry in the table
      if(timeCompare(entry->timestamp, oldestEntry->timestamp) < 0)
         oldestEntry = entry;
   }

   //The oldest entry is removed whenever the table runs out of space
   if(i >= HTTP_SERVER_NONCE_CACHE_SIZE)
      entry = oldestEntry;

   //Generate a new nonce
   error = context->settings.prngAlgo->read(context->settings.prngContext,
      nonce, HTTP_SERVER_NONCE_SIZE);

   //Check status code
   if(!error)
   {
      //Convert the byte array to hex string
      httpConvertArrayToHexString(nonce, HTTP_SERVER_NONCE_SIZE, entry->nonce);
      //Clear nonce count
      entry->count = 1;
      //Save the time at which the nonce was generated
      entry->timestamp = osGetSystemTime();

      //Copy the nonce to the output buffer
      strcpy(output, entry->nonce);
      //Return the length of the nonce excluding the NULL character
      *length = HTTP_SERVER_NONCE_SIZE * 2;
   }
   else
   {
      //Random number generation failed
      memset(entry, 0, sizeof(HttpNonceCacheEntry));
   }

   //Release exclusive access to the nonce cache
   osReleaseMutex(&context->nonceCacheMutex);
   //Return status code
   return error;

#else
   //Not implemented
   return ERROR_NOT_IMPLEMENTED;
#endif
}
示例#10
0
void dnsTick(void)
{
   error_t error;
   uint_t i;
   systime_t time;
   DnsCacheEntry *entry;

   //Get current time
   time = osGetSystemTime();

   //Acquire exclusive access to the DNS cache
   osAcquireMutex(&dnsCacheMutex);

   //Go through DNS cache
   for(i = 0; i < DNS_CACHE_SIZE; i++)
   {
      //Point to the current entry
      entry = &dnsCache[i];

      //Name resolution in progress?
      if(entry->state == DNS_STATE_IN_PROGRESS)
      {
         //The request timed out?
         if(timeCompare(time, entry->timestamp + entry->timeout) >= 0)
         {
            //Check whether the maximum number of retransmissions has been exceeded
            if(entry->retransmitCount > 0)
            {
#if (DNS_CLIENT_SUPPORT == ENABLED)
               //DNS resolver?
               if(entry->protocol == HOST_NAME_RESOLVER_DNS)
               {
                  //Retransmit DNS query
                  error = dnsSendQuery(entry);
               }
               else
#endif
#if (MDNS_CLIENT_SUPPORT == ENABLED)
               //mDNS resolver?
               if(entry->protocol == HOST_NAME_RESOLVER_MDNS)
               {
                  //Retransmit mDNS query
                  error = mdnsSendQuery(entry);
               }
               else
#endif
#if (NBNS_CLIENT_SUPPORT == ENABLED && IPV4_SUPPORT == ENABLED)
               //NetBIOS Name Service resolver?
               if(entry->protocol == HOST_NAME_RESOLVER_NBNS)
               {
                  //Retransmit NBNS query
                  error = nbnsSendQuery(entry);
               }
               else
#endif
               //Unknown protocol?
               {
                  error = ERROR_FAILURE;
               }

               //Query message successfully sent?
               if(!error)
               {
                  //Save the time at which the query message was sent
                  entry->timestamp = time;
                  //The timeout value is doubled for each subsequent retransmission
                  entry->timeout = MIN(entry->timeout * 2, entry->maxTimeout);
                  //Decrement retransmission counter
                  entry->retransmitCount--;
               }
               else
               {
                  //The entry should be deleted since name resolution has failed
                  dnsDeleteEntry(entry);
               }
            }
#if (DNS_CLIENT_SUPPORT == ENABLED)
            //DNS resolver?
            else if(entry->protocol == HOST_NAME_RESOLVER_DNS)
            {
               //Select the next DNS server
               entry->dnsServerNum++;
               //Initialize retransmission counter
               entry->retransmitCount = DNS_CLIENT_MAX_RETRIES;
               //Send DNS query
               error = dnsSendQuery(entry);

               //DNS message successfully sent?
               if(!error)
               {
                  //Save the time at which the query message was sent
                  entry->timestamp = time;
                  //Set timeout value
                  entry->timeout = DNS_CLIENT_INIT_TIMEOUT;
                  //Decrement retransmission counter
                  entry->retransmitCount--;
               }
               else
               {
                  //The entry should be deleted since name resolution has failed
                  dnsDeleteEntry(entry);
               }
            }
#endif
            else
            {
               //The maximum number of retransmissions has been exceeded
               dnsDeleteEntry(entry);
            }
         }
      }
      //Name successfully resolved?
      else if(entry->state == DNS_STATE_RESOLVED)
      {
         //Check the lifetime of the current DNS cache entry
         if(timeCompare(time, entry->timestamp + entry->timeout) >= 0)
         {
            //Periodically time out DNS cache entries
            dnsDeleteEntry(entry);
         }
      }
   }

   //Release exclusive access to the DNS cache
   osReleaseMutex(&dnsCacheMutex);
}
示例#11
0
文件: mld.c 项目: rpc-fw/analyzer
void mldProcessListenerQuery(NetInterface *interface, Ipv6PseudoHeader *pseudoHeader,
   const ChunkedBuffer *buffer, size_t offset, uint8_t hopLimit)
{
   uint_t i;
   size_t length;
   systime_t time;
   systime_t maxRespDelay;
   MldMessage *message;
   Ipv6FilterEntry *entry;

   //Retrieve the length of the MLD message
   length = chunkedBufferGetLength(buffer) - offset;

   //The message must be at least 24 octets long
   if(length < sizeof(MldMessage))
      return;

   //Point to the beginning of the MLD message
   message = chunkedBufferAt(buffer, offset);
   //Sanity check
   if(!message) return;

   //Debug message
   TRACE_INFO("MLD message received (%" PRIuSIZE " bytes)...\r\n", length);
   //Dump message contents for debugging purpose
   mldDumpMessage(message);

   //Make sure the source address of the message is a valid link-local address
   if(!ipv6IsLinkLocalUnicastAddr(&pseudoHeader->srcAddr))
      return;
   //Check the Hop Limit field
   if(hopLimit != MLD_HOP_LIMIT)
      return;

   //Get current time
   time = osGetTickCount();

   //The Max Resp Delay field specifies the maximum time allowed
   //before sending a responding report
   maxRespDelay = message->maxRespDelay * 10;

   //Acquire exclusive access to the IPv6 filter table
   osMutexAcquire(interface->ipv6FilterMutex);

   //Loop through filter table entries
   for(i = 0; i < interface->ipv6FilterSize; i++)
   {
      //Point to the current entry
      entry = &interface->ipv6Filter[i];

      //The link-scope all-nodes address (FF02::1) is handled as a special
      //case. The host starts in Idle Listener state for that address on
      //every interface and never transitions to another state
      if(ipv6CompAddr(&entry->addr, &IPV6_LINK_LOCAL_ALL_NODES_ADDR))
         continue;

      //A General Query is used to learn which multicast addresses have listeners
      //on an attached link. A Multicast-Address-Specific Query is used to learn
      //if a particular multicast address has any listeners on an attached link
      if(ipv6CompAddr(&message->multicastAddr, &IPV6_UNSPECIFIED_ADDR) ||
         ipv6CompAddr(&message->multicastAddr, &entry->addr))
      {
         //Delaying Listener state?
         if(entry->state == MLD_STATE_DELAYING_LISTENER)
         {
            //The timer has not yet expired?
            if(timeCompare(time, entry->timer) < 0)
            {
               //If a timer for the address is already running, it is reset to
               //the new random value only if the requested Max Response Delay
               //is less than the remaining value of the running timer
               if(maxRespDelay < (entry->timer - time))
               {
                  //Restart delay timer
                  entry->timer = time + mldRand(maxRespDelay);
               }
            }
         }
         //Idle Listener state?
         else if(entry->state == MLD_STATE_IDLE_LISTENER)
         {
            //Switch to the Delaying Listener state
            entry->state = MLD_STATE_DELAYING_LISTENER;
            //Delay the response by a random amount of time
            entry->timer = time + mldRand(maxRespDelay);
         }
      }
   }

   //Release exclusive access to the IPv6 filter table
   osMutexRelease(interface->ipv6FilterMutex);
}
示例#12
0
文件: Timer.cpp 项目: imace/kkS
bool TimeUtil::timout(TIME64 curTime, TIME64 deadlineTime)
{
    int64_t diff = timeCompare(deadlineTime, curTime);
    return diff > 0 ? true : false;
}