Exemplo n.º 1
0
    void CreateAnswer()
    {
      if (mSendAns && GetOffer().IsReceiving()) {
        mSendAns->AddToAnswer(GetOffer(), &GetAnswer());
      }

      if (mRecvAns && GetOffer().IsSending()) {
        mRecvAns->AddToAnswer(GetOffer(), &GetAnswer());
      }
    }
Exemplo n.º 2
0
    void CreateOffer()
    {
      if (mSendOff) {
        mSendOff->AddToOffer(&GetOffer());
      }

      if (mRecvOff) {
        mRecvOff->AddToOffer(&GetOffer());
      }
    }
Exemplo n.º 3
0
    void Negotiate()
    {
      std::cerr << "Offer SDP: " << std::endl;
      mOffer->Serialize(std::cerr);

      std::cerr << "Answer SDP: " << std::endl;
      mAnswer->Serialize(std::cerr);

      if (mSendAns && GetAnswer().IsSending()) {
        mSendAns->Negotiate(GetAnswer(), GetOffer());
      }

      if (mRecvAns && GetAnswer().IsReceiving()) {
        mRecvAns->Negotiate(GetAnswer(), GetOffer());
      }

      if (mSendOff && GetAnswer().IsReceiving()) {
        mSendOff->Negotiate(GetAnswer(), GetAnswer());
      }

      if (mRecvOff && GetAnswer().IsSending()) {
        mRecvOff->Negotiate(GetAnswer(), GetAnswer());
      }
    }
Exemplo n.º 4
0
TEST_F(JsepTrackTest, SimulcastAnswerer)
{
  Init(SdpMediaSection::kVideo);
  std::vector<JsepTrack::JsConstraints> constraints;
  constraints.push_back(MakeConstraints("foo", 40000));
  constraints.push_back(MakeConstraints("bar", 10000));
  mSendAns->SetJsConstraints(constraints);
  CreateOffer();
  // Add simulcast/rid to offer
  JsepTrack::AddToMsection(constraints, sdp::kRecv, &GetOffer());
  CreateAnswer();
  Negotiate();
  ASSERT_TRUE(mSendAns->GetNegotiatedDetails());
  ASSERT_EQ(2U, mSendAns->GetNegotiatedDetails()->GetEncodingCount());
  ASSERT_EQ("foo", mSendAns->GetNegotiatedDetails()->GetEncoding(0).mRid);
  ASSERT_EQ(40000U,
      mSendAns->GetNegotiatedDetails()->GetEncoding(0).mConstraints.maxBr);
  ASSERT_EQ("bar", mSendAns->GetNegotiatedDetails()->GetEncoding(1).mRid);
  ASSERT_EQ(10000U,
      mSendAns->GetNegotiatedDetails()->GetEncoding(1).mConstraints.maxBr);
}
Exemplo n.º 5
0
// OTCron calls this regularly, which is my chance to expire, etc.
// Return True if I should stay on the Cron list for more processing.
// Return False if I should be removed and deleted.
bool OTTrade::ProcessCron()
{
    // Right now Cron is called 10 times per second.
    // I'm going to slow down all trades so they are once every
    // GetProcessInterval()
    if (GetLastProcessDate() > OT_TIME_ZERO) {
        // (Default ProcessInterval is 1 second, but Trades will use 10 seconds,
        // and Payment Plans will use an hour or day.)
        if (OTTimeGetTimeInterval(OTTimeGetCurrentTime(),
                                  GetLastProcessDate()) <= GetProcessInterval())
            return true;
    }
    
    // Keep a record of the last time this was processed.
    // (NOT saved to storage, only used while the software is running.)
    // (Thus no need to release signatures, sign contract, save contract, etc.)
    SetLastProcessDate(OTTimeGetCurrentTime());

    // PAST END DATE?
    // First call the parent's version (which this overrides) so it has
    // a chance to check its stuff. Currently it checks IsExpired().
    if (!ot_super::ProcessCron())
        return false; // It's expired or flagged for removal--remove it from
                      // Cron.

    // You might ask, why not check here if this trade is flagged for removal?
    // Supposedly the answer is, because it's only below that I have the market
    // pointer,
    // and am able to remove the corresponding trade from the market.
    // Therefore I am adding a hook for "onRemoval" so that Objects such as
    // OTTrade ALWAYS
    // have the opportunity to perform such cleanup, without having to juggle
    // such logic.

    // REACHED START DATE?
    // Okay, so it's not expired. But might not have reached START DATE yet...
    if (!VerifyCurrentDate())
        return true; // The Trade is not yet valid, so we return. BUT, we return
                     //  true, so it will stay on Cron until it BECOMES valid.

    // TRADE-specific stuff below.

    bool bStayOnMarket =
        true; // by default stay on the market (until some rule expires me.)

    Identifier OFFER_MARKET_ID;
    OTMarket* market = nullptr;

    // If the Offer is already active on a market, then I already have a pointer
    // to
    // it. This function returns that pointer. If nullptr, it tries to find the
    // offer on
    // the market and then sets the pointer and returns. If it can't find it, IT
    // TRIES
    // TO ADD IT TO THE MARKET and sets the pointer and returns it.
    OTOffer* offer = GetOffer(
        &OFFER_MARKET_ID, &market); // Both of these parameters are optional.

    // In this case, the offer is NOT on the market.
    // Perhaps it wasn't ready to activate yet.
    if (offer == nullptr) {
        
        // The offer SHOULD HAVE been on the market, since we're within the
        // valid range,
        // and GetOffer adds it when it's not already there.

        //        otErr << "OTTrade::ProcessCron: Offer SHOULD have been on
        // Market. I might ASSERT this.\n"; // comment this out

        // Actually! If it's a Stop Order, then it WOULD be within the valid
        // range, yet would
        // not yet have activated. So I don't want to log some big error every
        // time a stop order
        // checks its prices.
    }
    else if (market == nullptr) {
        
        // todo. (This will already leave a log above in GetOffer somewhere.)
        //        otErr << "OTTrade::ProcessCron: Market was nullptr.\n"; //
        // comment this out
    }
    else // If a valid pointer was returned, that means the offer is on the
           // market.
    {
        // Make sure it hasn't already been flagged by someone else...
        if (IsFlaggedForRemoval()) // This is checked above in
                                   // OTCronItem::ProcessCron().
            bStayOnMarket = false; // I'm leaving the check here in case the
                                   // flag was set since then.

        else // Process it!  <===================
        {
            otInfo << "Processing trade: " << GetTransactionNum() << ".\n";

            bStayOnMarket = market->ProcessTrade(*this, *offer);
            // No need to save the Trade or Offer, since they will
            // be saved inside this call if they are changed.
        }
    }

    // Return True if I should stay on the Cron list for more processing.
    // Return False if I should be removed and deleted.
    return bStayOnMarket; // defaults true, so if false, that means someone is
                          // removing it for a reason.
}