Exemplo n.º 1
0
TorController::~TorController()
{
    if (reconnect_ev)
        event_del(reconnect_ev);
    if (service.IsValid()) {
        RemoveLocal(service);
    }
}
Exemplo n.º 2
0
int gmShellPlink::StageIn(const gmdArrayString& locfiles, pCSTR remdir, unsigned flags){
  gmdString tempdir, src, err;
  gmdArrayString srclist;

  if( StageIn_begin(NULL, remdir, flags) )
    return StageIn_end(NULL, remdir, flags);

  for(unsigned i=0; i<locfiles.GetCount(); i++) {
    gmdString lfile = locfiles[i];
    if( lfile.IsEmpty() ) continue;
    lfile.Replace("/", "\\");

    if( has_wildcards(lfile) ) {
      // List all files explicitly if lfile contains wildcards
      gmdArrayString filelist;
      unsigned nfiles = files_by_mask(lfile, filelist, flags);
      if(nfiles)
        for(unsigned k=0; k<nfiles; k++) srclist.Add(filelist[k]);
      else
        set_err(NO_INPUT_FILE, fmt("%s: no such files", (pCSTR)lfile.c_str()));
    }
    else if( path_exists(lfile, flags) )
      srclist.Add(lfile);
    else
      set_err(NO_INPUT_FILE, fmt("%s: no sich file or directory", (pCSTR)lfile.c_str()));
  }

  if( !srclist.IsEmpty() ) {
    if(flags & TEXT) {
      // Convert text files and store them in the temporary dir
      assert_no_recursive(flags);  // combination RECURSIVE & TEXT is not supported!
      tempdir = GetTempDir();
      //dos2unix(srclist, tempdir);
      conv_files(srclist, tempdir, dos2unix);
      src = tempdir + "\\*.*";
    } else {
      // prepare the space separated file list for PLINK
      for(unsigned i=0; i<srclist.GetCount(); i++)
        src += (i>0 ? "\" \"" : "") + srclist[i];
    }

    // Copy files
    if(!error_code) {
      gmdString args = (flags & RECURSIVE) ? "-r \"" : "\"";
      args += src + "\" \"" + userhost + ':' + rem_path_subst(remdir) + "\"";
      pscp_execute(args);
    }

    if( !tempdir.IsEmpty() ) remove_local(tempdir);

    if(!error_code && (flags & MOVE))  // custom move (not using StageIn_end)
      for(unsigned i=0; i<srclist.GetCount(); i++) RemoveLocal(srclist[i], flags);
  }

  return StageIn_end(NULL, remdir, flags);
}
Exemplo n.º 3
0
TorController::~TorController()
{
    if (reconnect_ev) {
        event_free(reconnect_ev);
        reconnect_ev = 0;
    }
    if (service.IsValid()) {
        RemoveLocal(service);
    }
}
Exemplo n.º 4
0
void TorController::disconnected_cb(TorControlConnection& conn)
{
    // Stop advertising service when disconnected
    if (service.IsValid())
        RemoveLocal(service);
    service = CService();
    if (!reconnect)
        return;

    LogPrint("tor", "tor: Not connected to Tor control port %s, trying to reconnect\n", target);

    // Single-shot timer for reconnect. Use exponential backoff.
    struct timeval time = MillisToTimeval(int64_t(reconnect_timeout * 1000.0));
    if (reconnect_ev)
        event_add(reconnect_ev, &time);
    reconnect_timeout *= RECONNECT_TIMEOUT_EXP;
}
Exemplo n.º 5
0
skv_status_t
skv_local_kv_inmem::Insert( skv_cmd_RIU_req_t *aReq,
                            skv_status_t aCmdStatus,
                            skv_lmr_triplet_t *aStoredValueRep,
                            skv_lmr_triplet_t *aValueRDMADest,
                            skv_local_kv_cookie_t *aCookie )
{
  skv_status_t status = SKV_ERRNO_UNSPECIFIED_ERROR;

  int KeySize = aReq->mKeyValue.mKeySize;
  int ValueSize = aReq->mKeyValue.mValueSize;
  int TotalValueSize = ValueSize + aReq->mOffset;

  AssertLogLine( TotalValueSize >= 0 &&
                 TotalValueSize < SKV_VALUE_LIMIT )
    << "skv_local_kv_inmem::Insert():: ERROR: "
    << "TotalValueSize: " << TotalValueSize
    << EndLogLine;

  // Check if there's enough space for Key/Value
  int KeyValueSize = KeySize + TotalValueSize;

  BegLogLine( SKV_LOCAL_KV_BACKEND_LOG)
    << "skv_local_kv_inmem::Insert():: Entering with: "
    << " KeySize: " << KeySize
    << " ValueSize: " << ValueSize
    << " TotalValueSize: " << TotalValueSize
    << " KeyValueSize: " << KeyValueSize
    << " Flags: " << (void*)aReq->mFlags
    << EndLogLine;

  int LocalValueSize = aStoredValueRep->GetLen();

  /********************************************************
   * Record Exists
   ********************************************************/
  if( aCmdStatus == SKV_SUCCESS )
  {
    switch( aReq->mFlags & (SKV_COMMAND_RIU_INSERT_EXPANDS_VALUE
        | SKV_COMMAND_RIU_INSERT_OVERWRITE_VALUE_ON_DUP
        | SKV_COMMAND_RIU_UPDATE
        | SKV_COMMAND_RIU_APPEND) )
    {
      case SKV_COMMAND_RIU_INSERT_OVERWRITE_VALUE_ON_DUP:
        /********************************************************
         * we overwrite WITHIN EXISTING RECORD BOUNDS ONLY
         ********************************************************/

        BegLogLine( SKV_LOCAL_KV_BACKEND_LOG )
            << "skv_local_kv_inmem::Insert():: OVERWRITE_ON_DUP"
            << " ValueSize: " << ValueSize
            << " offs: " << aReq->mOffset
            << EndLogLine;

        if( LocalValueSize < TotalValueSize )
        {
          status = SKV_ERRNO_VALUE_TOO_LARGE;
          break;
        }

        aValueRDMADest->InitAbs( aStoredValueRep->GetLMRHandle(),
                                 (char *) aStoredValueRep->GetAddr() + aReq->mOffset,
                                 ValueSize );
        status = SKV_SUCCESS;
        break;

      case SKV_COMMAND_RIU_INSERT_EXPANDS_VALUE:
        /********************************************************
         * Record Exists, Expansion Allowed
         ********************************************************/

        // Expandable insert option is set and the record is found
        // Do we need to expand?

        BegLogLine( SKV_LOCAL_KV_BACKEND_LOG )
          << "skv_local_kv_inmem::Insert():: EXPAND_VALUE"
          << " LocalValueSize: " << LocalValueSize
          << " ValueSize: " << ValueSize
          << " TotalValueSize: " << TotalValueSize
          << EndLogLine;

        if( TotalValueSize > LocalValueSize )
        {
          if( !(aReq->mFlags & SKV_COMMAND_RIU_INSERT_OVERLAPPING) )
          {
            BegLogLine( SKV_LOCAL_KV_BACKEND_LOG )
              << "skv_local_kv_inmem::Insert():: overlapping inserts not allowed "
              << " Req->mOffset: " << aReq->mOffset
              << " LocalValueSize: " << LocalValueSize
              << " requires: SKV_COMMAND_RIU_INSERT_OVERLAPPING to be set"
              << EndLogLine;

            status = SKV_ERRNO_INSERT_OVERLAP;
            break;
          }

          /***************************************************************
           * Expand Value
           **************************************************************/
          // Allocate new
          skv_lmr_triplet_t NewRecordAllocRep;

          status = AllocateAndMoveKey( aReq,
                                       KeyValueSize,
                                       &NewRecordAllocRep,
                                       &mPDSManager );

          if( status != SKV_SUCCESS )
            break;

          // copy existing value to new allocated record
          char* RecordPtr = (char *) NewRecordAllocRep.GetAddr() + KeySize;

          memcpy( RecordPtr,
                  (void *) aStoredValueRep->GetAddr(),
                  LocalValueSize );

          RecordPtr += aReq->mOffset;   // LocalValueSize;

          // Prepare LMR to cover the new to read fraction of the value only
          aValueRDMADest->InitAbs( NewRecordAllocRep.GetLMRHandle(),
                                   RecordPtr,
                                   ValueSize );

          // Remove old record and deallocate space
          status = RemoveLocal( aReq,
                                KeySize,
                                (char *) aStoredValueRep->GetAddr(),
                                &mPDSManager );

          // insert new record
          status = InsertLocal( aReq,
                                (char *) NewRecordAllocRep.GetAddr(),
                                KeySize,
                                TotalValueSize,
                                &mPDSManager,
                                mMyRank );

          /*******************************************************************/
        }
        else
        {
          // Record was found, but no expansion is needed
          // Just make sure that the rdma_read is done to the
          // appropriate offset

          aValueRDMADest->InitAbs( aStoredValueRep->GetLMRHandle(),
                                   (char *) aStoredValueRep->GetAddr() + aReq->mOffset,
                                   ValueSize );
          status = SKV_SUCCESS;
        }

        break;
        /********************************************************/

      case SKV_COMMAND_RIU_UPDATE:
        /********************************************************
         * Record exists and we update with POTENTIAL REALLOCATION of the record
         ********************************************************/

        // if the new size is exactly the previous size, there's nothing to adjust
        // just make sure the LMR is pointing to the right location
        if( (uint64_t)ValueSize == aStoredValueRep->GetLen() )
        {
          BegLogLine( SKV_LOCAL_KV_BACKEND_LOG )
            << "skv_local_kv_inmem::Insert():: UPDATE same length record, overwriting..."
            << " ValueSize: " << ValueSize
            << " offs: " << aReq->mOffset
            << EndLogLine;

          aValueRDMADest->InitAbs( aStoredValueRep->GetLMRHandle(),
                                   (char *) aStoredValueRep->GetAddr() + aReq->mOffset,
                                   ValueSize );
          status = SKV_SUCCESS;
        }
        // reallocate, copy and insert new updated record, if the size is different
        else
        {
          BegLogLine( SKV_LOCAL_KV_BACKEND_LOG )
            << "skv_local_kv_inmem::Insert():: UPDATE different length record, reallocating..."
            << " ValueSize: " << ValueSize
            << " offs: " << aReq->mOffset
            << EndLogLine;

          status = RemoveLocal( aReq,
                                KeySize,
                                (char *) aStoredValueRep->GetAddr(),
                                &mPDSManager );

          skv_lmr_triplet_t NewRecordAllocRep;

          status = AllocateAndMoveKey( aReq,
                                       KeyValueSize,
                                       &NewRecordAllocRep,
                                       &mPDSManager );

          if( status != SKV_SUCCESS )
            break;

          aValueRDMADest->InitAbs( NewRecordAllocRep.GetLMRHandle(),
                                   (char *) NewRecordAllocRep.GetAddr() + KeySize + aReq->mOffset,
                                   ValueSize );

          status = InsertLocal( aReq,
                                (char *) NewRecordAllocRep.GetAddr(),
                                KeySize,
                                TotalValueSize,
                                &mPDSManager,
                                mMyRank );

        }
        break;
        /********************************************************/

      case SKV_COMMAND_RIU_APPEND:
        /********************************************************
         * Record Exists, Append new data
         ********************************************************/

        TotalValueSize = LocalValueSize + ValueSize;

        KeyValueSize = KeySize + TotalValueSize;

        BegLogLine( SKV_LOCAL_KV_BACKEND_LOG )
          << "skv_local_kv_inmem::Insert():: APPEND "
          << " LocalValueSize: " << LocalValueSize
          << " ValueSize: " << ValueSize
          << " TotalValueSize: " << TotalValueSize
          << EndLogLine;

        if( TotalValueSize > LocalValueSize )
        {
          /***************************************************************
           * Expand Value
           **************************************************************/
          // Allocate new
          skv_lmr_triplet_t NewRecordAllocRep;

          status = AllocateAndMoveKey( aReq,
                                       KeyValueSize,
                                       &NewRecordAllocRep,
                                       &mPDSManager );

          if( status != SKV_SUCCESS )
            break;

          char* RecordPtr = (char *) NewRecordAllocRep.GetAddr() + KeySize;

          memcpy( RecordPtr,
                  (void *) aStoredValueRep->GetAddr(),
                  LocalValueSize );

          // setup to add new record
          RecordPtr += LocalValueSize;

          // rdma read only the new record data
          aValueRDMADest->InitAbs( NewRecordAllocRep.GetLMRHandle(),
                                   RecordPtr,
                                   ValueSize );

          status = RemoveLocal( aReq,
                                KeySize,
                                (char *) aStoredValueRep->GetAddr(),
                                &mPDSManager );

          status = InsertLocal( aReq,
                                (char *) NewRecordAllocRep.GetAddr(),
                                KeySize,
                                TotalValueSize,
                                &mPDSManager,
                                mMyRank );

          AssertLogLine( status == SKV_SUCCESS )
            << "skv_local_kv_inmem::Insert():: ERROR: "
            << " status: " << skv_status_to_string( status )
            << EndLogLine;
          /*******************************************************************/
        }
        else
        {
          // Record was found, but no expansion is needed
          // Just make sure that the rdma_read is done to the
          // appropriate offset

          aValueRDMADest->InitAbs( aStoredValueRep->GetLMRHandle(),
                                   (char *) aStoredValueRep->GetAddr() + aReq->mOffset,
                                   ValueSize );
        }

        break;
        /********************************************************/

      default:   // mFlags
        /********************************************************
         * Record Exists and no special flags provided: error response
         ********************************************************/

        BegLogLine( SKV_LOCAL_KV_BACKEND_LOG )
          << " skv_local_kv_inmem::Insert(): record exists, returning ERRNO"
          << EndLogLine;

        status = SKV_ERRNO_RECORD_ALREADY_EXISTS;

        break;
        /********************************************************/

    }
  }
  else
  {
    /********************************************************
     * Record Does NOT Exist, do a general insert
     ********************************************************/

    /****************************************
     * Allocate space for the key and value
     ****************************************/
    skv_lmr_triplet_t NewRecordAllocRep;

    BegLogLine( SKV_LOCAL_KV_BACKEND_LOG)
      << "skv_local_kv_inmem::Insert():: "
      << " Req->mKeyValue: " << aReq->mKeyValue
      << EndLogLine;

    status = AllocateAndMoveKey( aReq,
                                 KeyValueSize,
                                 &NewRecordAllocRep,
                                 &mPDSManager );

    if( status == SKV_SUCCESS )
    {
      // if no EXPAND requested the requested offset has to be 0
      if( !(aReq->mFlags & SKV_COMMAND_RIU_INSERT_EXPANDS_VALUE) )
        AssertLogLine( aReq->mOffset == 0 )
          << "skv_local_kv_inmem::Insert():: ERROR: "
          << " Req->mOffset: " << aReq->mOffset
          << EndLogLine;

      aValueRDMADest->InitAbs( NewRecordAllocRep.GetLMRHandle(),
                               (char *) NewRecordAllocRep.GetAddr() + KeySize + aReq->mOffset,
                               ValueSize );

      status = InsertLocal( aReq,
                            (char *) NewRecordAllocRep.GetAddr(),
                            KeySize,
                            TotalValueSize,
                            &mPDSManager,
                            mMyRank );

    }
  }
  /***********************************************************************/

  if( status != SKV_SUCCESS )
    return status;

  /*******************************************************************
   * Get the data copied or rdma'd into the new record
   ******************************************************************/
  if( aReq->mFlags & SKV_COMMAND_RIU_INSERT_KEY_VALUE_FIT_IN_CTL_MSG )
  {
    BegLogLine( SKV_LOCAL_KV_BACKEND_LOG )
      << "skv_local_kv_inmem::Insert():: inserting value with FIT_IN_CTL_MSG"
      << " len: " << ValueSize
      << EndLogLine;

    memcpy( (void *) aValueRDMADest->GetAddr(),
            &aReq->mKeyValue.mData[KeySize],
            ValueSize );

    BegLogLine(SKV_LOCAL_KV_BACKEND_LOG)
      << "Value placed in memory at " << (void *)(aValueRDMADest->GetAddr())
      << EndLogLine ;
  }
  else
    // signal that this command is going to require async data transfer
    status = SKV_ERRNO_NEED_DATA_TRANSFER;

  return status;
}