TEST_F(P2pSessionTest, testBroadcast) { TestRpcPlugIn* peerRpcPlugIn1; TestP2pEventHandler peerEventHandler1; boost::scoped_ptr<P2pSession> peer1( P2pSessionFactory::create(2, peerEventHandler1)); peerRpcPlugIn1 = new TestRpcPlugIn; PlugInPtr plugIn1(peerRpcPlugIn1); peer1->attach(plugIn1); EXPECT_TRUE(peer1->open(ACE_DEFAULT_SERVER_PORT + 1)); peer1->connect(getHostAddresses()); for (int i = 0; i < (2 * 3); ++i) { peer1->tick(); hostSession_->tick(); } TestRpcPlugIn* peerRpcPlugIn2; TestP2pEventHandler peerEventHandler2; boost::scoped_ptr<P2pSession> peer2( P2pSessionFactory::create(3, peerEventHandler2)); peerRpcPlugIn2 = new TestRpcPlugIn; PlugInPtr plugIn2(peerRpcPlugIn2); peer2->attach(plugIn2); EXPECT_TRUE(peer2->open(ACE_DEFAULT_SERVER_PORT + 2)); peer2->connect(getHostAddresses()); for (int i = 0; i < (2 * 4); ++i) { peer1->tick(); peer2->tick(); hostSession_->tick(); } EXPECT_EQ(int(hostSession_->getPeerCount()), int(peer1->getPeerCount())); hostRpcPlugIn_->hello("hi"); for (int i = 0; i < (2 * 4); ++i) { hostSession_->tick(); peer1->tick(); peer2->tick(); } EXPECT_EQ("hi", peerRpcPlugIn1->getLastWorld()); EXPECT_EQ(PeerId(1), peerRpcPlugIn1->getLastPeerId()); EXPECT_EQ("hi", peerRpcPlugIn2->getLastWorld()); EXPECT_EQ(PeerId(1), peerRpcPlugIn2->getLastPeerId()); }
std::unique_ptr<ContentMemento> Memento::DefaultContent( PeerId peerId, Section section) { Expects(peerId != 0); auto peer = Auth().data().peer(peerId); if (auto to = peer->migrateTo()) { peer = to; } auto migrated = peer->migrateFrom(); peerId = peer->id; auto migratedPeerId = migrated ? migrated->id : PeerId(0); switch (section.type()) { case Section::Type::Profile: return std::make_unique<Profile::Memento>( peerId, migratedPeerId); case Section::Type::Media: return std::make_unique<Media::Memento>( peerId, migratedPeerId, section.mediaType()); case Section::Type::CommonGroups: Assert(peerIsUser(peerId)); return std::make_unique<CommonGroups::Memento>( peerToUser(peerId)); case Section::Type::Members: return std::make_unique<Members::Memento>( peerId, migratedPeerId); } Unexpected("Wrong section type in Info::Memento::DefaultContent()"); }
void IntroSignup::mousePressEvent(QMouseEvent *e) { mouseMoveEvent(e); if (QRect(_phLeft, _phTop, st::introPhotoSize, st::introPhotoSize).contains(e->pos())) { QStringList imgExtensions(cImgExtensions()); QString filter(qsl("Image files (*") + imgExtensions.join(qsl(" *")) + qsl(");;All files (*.*)")); QImage img; QString file; QByteArray remoteContent; if (filedialogGetOpenFile(file, remoteContent, lang(lng_choose_images), filter)) { if (!remoteContent.isEmpty()) { img = App::readImage(remoteContent); } else { if (!file.isEmpty()) { img = App::readImage(file); } } } else { return; } if (img.isNull() || img.width() > 10 * img.height() || img.height() > 10 * img.width()) { showError(lang(lng_bad_photo)); return; } PhotoCropBox *box = new PhotoCropBox(img, PeerId(0)); connect(box, SIGNAL(ready(const QImage &)), this, SLOT(onPhotoReady(const QImage &))); Ui::showLayer(box); }
TEST_F(P2pSessionTest, testLimitPeers) { const int maxPeers = 2; hostSession_->close(); openHost("", maxPeers); const int peerCount = 2; P2pSession* peers[peerCount]; TestP2pEventHandler eventHandlers[peerCount]; for (int i = 0; i < peerCount; ++i) { peers[i] = P2pSessionFactory::create(PeerId(2 + i), eventHandlers[i]); EXPECT_TRUE(peers[i]->open(ACE_DEFAULT_SERVER_PORT + (u_short)i + 1)) << "#" << i << "peer"; peers[i]->connect(getHostAddresses()); } for (int x = 0; x < (peerCount * 8); ++x) { for (int i = 0; i < peerCount; ++i) { peers[i]->tick(); } hostSession_->tick(); } EXPECT_EQ(maxPeers, int(hostSession_->getPeerCount())); EXPECT_EQ(maxPeers - 1, int(hostEventHandler_.getConnectedPeers())); for (int i = 0; i < peerCount; ++i) { delete peers[i]; } }
void MacPrivate::notifyClicked(unsigned long long peer) { History *history = App::history(PeerId(peer)); App::wnd()->showFromTray(); App::wnd()->hideSettings(); App::main()->showPeer(history->peer->id, false, true); App::wnd()->notifyClear(history); }
TEST_F(P2pSessionTest, testOpen) { EXPECT_EQ(1, int(hostSession_->getPeerCount())); EXPECT_EQ(PeerId(1), hostSession_->getPeerId()); EXPECT_EQ(0, int(hostSession_->getStats(1).sentReliablePackets_)); EXPECT_EQ(0, int(hostSession_->getStats(1).receivedReliablePackets_)); }
PeerId PeerFromMessage(const MTPmessage &message) { return message.match([](const MTPDmessageEmpty &) { return PeerId(0); }, [](const auto &message) { auto from_id = message.has_from_id() ? peerFromUser(message.vfrom_id) : 0; auto to_id = peerFromMTP(message.vto_id); auto out = message.is_out(); return (out || !peerIsUser(to_id)) ? to_id : from_id; }); }
void MacPrivate::notifyClicked(unsigned long long peer, int msgid) { History *history = App::history(PeerId(peer)); App::wnd()->showFromTray(); if (App::passcoded()) { App::wnd()->setInnerFocus(); App::wnd()->notifyClear(); } else { App::wnd()->hideSettings(); bool tomsg = !history->peer->isUser() && (msgid > 0); if (tomsg) { HistoryItem *item = App::histItemById(peerToChannel(PeerId(peer)), MsgId(msgid)); if (!item || !item->mentionsMe()) { tomsg = false; } } App::main()->showPeerHistory(history->peer->id, tomsg ? msgid : ShowAtUnreadMsgId); App::wnd()->notifyClear(history); } }
void MacPrivate::notifyReplied(unsigned long long peer, int msgid, const char *str) { History *history = App::history(PeerId(peer)); MainWidget::MessageToSend message; message.history = history; message.textWithTags = { QString::fromUtf8(str), TextWithTags::Tags() }; message.replyTo = (msgid > 0 && !history->peer->isUser()) ? msgid : 0; message.broadcast = false; message.silent = false; App::main()->sendMessage(message); }
TEST_F(P2pSessionTest, testMultiplePeerConnect) { typedef boost::shared_ptr<P2pSession> P2pSessionPtr; typedef std::vector<P2pSessionPtr> P2pSessions; const int peerCount = 3; P2pSessions peers; peers.reserve(peerCount); TestP2pEventHandler eventHandlers[peerCount]; for (int i = 0; i < peerCount; ++i) { P2pSessionPtr peer( P2pSessionFactory::create(PeerId(2 + i), eventHandlers[i])); EXPECT_TRUE(peer->open(ACE_DEFAULT_SERVER_PORT + (u_short)i + 1)) << "#" << i << " peer"; peer->connect(getHostAddresses()); peer->tick(); peers.push_back(peer); } for (int x = 0; x < (peerCount * 8); ++x) { for (int i = 0; i < peerCount; ++i) { peers[i]->tick(); } hostSession_->tick(); pause(1); } EXPECT_EQ(peerCount + 1, int(hostSession_->getPeerCount())); EXPECT_EQ(peerCount, int(hostEventHandler_.getConnectedPeers())) << "host - connected peer count"; for (int i = 0; i < peerCount; ++i) { EXPECT_EQ(peerCount + 1, int(peers[i]->getPeerCount())) << "#" << i << " peer"; const PeerStats stats = peers[i]->getStats(1); EXPECT_EQ(peerCount, int(eventHandlers[i].getConnectedPeers())) << "#" << i << " peer - connected peer count"; } }
void MacPrivate::notifyReplied(unsigned long long peer, int msgid, const char *str) { History *history = App::history(PeerId(peer)); App::main()->sendMessage(history, QString::fromUtf8(str), (msgid > 0 && !history->peer->isUser()) ? msgid : 0, false); }
void MacPrivate::notifyReplied(unsigned long long peer, const char *str) { History *history = App::history(PeerId(peer)); App::main()->sendMessage(history, QString::fromUtf8(str)); }