bool MP1Node::recvJoinReq(void *env, char *data, int size) {
    if (size < (int)(sizeof(memberNode->addr.addr) + sizeof(long))) {
#ifdef DEBUGLOG
        log->LOG(&memberNode->addr, "Message JOINREQ received with size wrong. Ignored.");
#endif
        return false;
    }

    Address joinaddr;
    long heartbeat;

    memcpy(joinaddr.addr, data, sizeof(memberNode->addr.addr));
    memcpy(&heartbeat, data + sizeof(memberNode->addr.addr), sizeof(long));

//#ifdef DEBUGLOG
//    log->LOG(&memberNode->addr, "JOINREQ received from: %s heartbeat: %li", joinaddr.getAddress().c_str(), heartbeat);
//#endif

    int id = *(int*)(&joinaddr.addr);
    int port = *(short*)(&joinaddr.addr[4]);

    updateMember(id, port, heartbeat);

    sendMemberList("JOINREP", JOINREP, &joinaddr);
    return true;
}
Esempio n. 2
0
bool MP1Node::recvMemberList(const char * label, void *env, char *data, int size)
{
if (size < (int)(sizeof(long))) {
#ifdef DEBUGLOG
log->LOG(&memberNode->addr, "Message %s received with size wrong. Ignored. size[%s]", label, size);
#endif
return false;
}
long members;
memcpy(&members, data, sizeof(long));
data += sizeof(long);
size -= sizeof(long);
//log->LOG(&memberNode->addr, "Message %s received: SIZE[%li]", label, members);
if (size < (int)(members * (sizeof(int) + sizeof(short) + sizeof(log)))) {
#ifdef DEBUGLOG
log->LOG(&memberNode->addr, "Message %s received with size wrong. Ignored.", label);
#endif
return false;
}
MemberListEntry member;
for (long i = 0; i < members; i++) {
//log->LOG(&memberNode->addr, "Message %s received: i[%li]", label, i);
memcpy(&member.id, data, sizeof(int));
data += sizeof(int);
memcpy(&member.port, data, sizeof(short));
data += sizeof(short);
memcpy(&member.heartbeat, data, sizeof(long));
data += sizeof(long);
member.timestamp = par->getcurrtime();
//logMemberListEntry(member);
updateMember(member);
}
return true;
}
Esempio n. 3
0
void NGLScene::paintGL()
{
  // clear the screen and depth buffer
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glViewport(0,0,m_width,m_height);
  QString text;
  m_text->setColour(0,0,0);
  m_text->renderText(10,10,text);
  text.sprintf("Number of birds = %d", makerBirds.BirdID.size());
  m_text->renderText(10,25,text);
  m_lightPos = avoidWall->getPosition();
  m_transform.setPosition(followSphere->getPosition());
  m_transform.setRotation(0.0f, 0.0f, 0.0f);
  m_transform.setScale(2.0f, 2.0f, 2.0f);
  loadToShader();
  followSphere->draw();
  m_transform.setPosition(avoidSphere->getPosition());
  m_transform.setScale(3.0f, 3.0f, 3.0f);
  loadToShader();
  avoidSphere->draw();
//  m_transform.setPosition(avoidPyramid->getPosition());
//  m_transform.setScale(3.0f, 3.0f, 3.0f);
//  loadToShader();
//  avoidPyramid->draw();
  m_transform.setPosition(avoidWall->getPosition());
  loadToShader();
  avoidWall->draw();
//  m_transform.setPosition(avoidTorus->getPosition());
//  m_transform.setScale(3.0f, 3.0f, 3.0f);
//  loadToShader();
//  avoidTorus->draw();
  m_transform.setScale(1.0f, 1.0f, 1.0f);
//  std::cout <<"size " <<makerBirds.BirdID.size() << "\n";
  for(unsigned int i = 0; i < makerBirds.BirdID.size(); i++)
  {
    m_transform.setPosition(getMemberPosition(*makerBirds.BirdID[i]));
//    m_transform.setRotation(getMemberForwardVector(*makerBirds.BirdID[i]) + ngl::Vec3(90.0f, 0.0f, 0.0f));
    loadToShader();
    drawMember(*makerBirds.BirdID[i]);
    updateMember(*makerBirds.BirdID[i]);
  }
//  std::cout<<"cam "<<cam.getPosition().m_x<<"\n";
//  std::cout<<"sphere "<<followSphere->getPosition().m_x<<"\n";

}
Esempio n. 4
0
void SecurityManager::banIP(const QString &ip, int time)
{
    if (bannedIPs.contains(ip)) {
        return;
    }

    bannedIPs.insert(ip, QDateTime::currentDateTimeUtc().toTime_t() + time * 60);

    QStringList aliases = membersForIp(ip);

    if (aliases.length() > 0) {
        foreach(const QString &name, aliases) {
            Member m = member(name);
            m.ban(time);

            bannedMembers.insert(name.toLower(), std::make_pair(m.ip, m.ban_expire_time));

            updateMember(m);
        }
Esempio n. 5
0
bool MP1Node::recvJoinReq(void *env, char *data, int size) {//kiem tra kich thuoc goi tin co hop le
    if (size < (int)(sizeof(memberNode->addr.addr) + sizeof(long))) {
#ifdef DEBUGLOG
        log->LOG(&memberNode->addr, "Message JOINREQ received with wrong size. Ignored.");
#endif
        return false;
    }

    Address joinaddr;
    long heartbeat;

    memcpy(joinaddr.addr, data, sizeof(memberNode->addr.addr));
    memcpy(&heartbeat, data + sizeof(memberNode->addr.addr), sizeof(long));
    int id = *(int*)(&joinaddr.addr);
    int port = *(short*)(&joinaddr.addr[4]);

    updateMember(id, port, heartbeat);

    sendMemberList("JOINREP", JOINREP, &joinaddr);
    return true;
}
Esempio n. 6
0
void SecurityManager::banIP(const QString &ip, int time)
{
    if (bannedIPs.contains(ip) && (time != 0 || bannedIPs.find(ip).value() == 0)) { //overwrite if tempbanned and current ban is perm
        return;
    }

    if (time <= 0) {
        bannedIPs.insert(ip, 0);
    } else {
        bannedIPs.insert(ip, QDateTime::currentDateTimeUtc().toTime_t() + time * 60);
    }

    QStringList aliases = membersForIp(ip);

    if (aliases.length() > 0) {
        foreach(const QString &name, aliases) {
            Member m = member(name);
            m.ban(time);

            bannedMembers.insert(name.toLower(), std::make_pair(m.ip, m.ban_expire_time));

            updateMember(m);
        }
Esempio n. 7
0
void MainWindow::addMember()
{
    MemberDlg *memberDlg = new MemberDlg("FamilyMember");
    connect(memberDlg,SIGNAL(updateFamilyMember()),this,SLOT(updateMember()));
    memberDlg->show();
}
Esempio n. 8
0
void MP1Node::updateMember(MemberListEntry& member)
{
    updateMember(member.getid(), member.getport(), member.getheartbeat());
}