fixed load/save of new group ids and backward compatibility with FriendList

This commit is contained in:
csoler 2016-07-06 22:02:56 -04:00
parent 01c0d2f0f1
commit 269f9457be
7 changed files with 124 additions and 40 deletions

View File

@ -2065,7 +2065,10 @@ bool p3PeerMgrIMPL::saveList(bool &cleanup, std::list<RsItem *>& saveData)
/* save groups */ /* save groups */
for ( std::map<RsNodeGroupId,RsGroupInfo>::iterator groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt) for ( std::map<RsNodeGroupId,RsGroupInfo>::iterator groupIt = groupList.begin(); groupIt != groupList.end(); ++groupIt)
saveData.push_back(new RsNodeGroupItem(groupIt->second)); // no delete {
RsNodeGroupItem *itm = new RsNodeGroupItem(groupIt->second);
saveData.push_back(itm) ;
}
return true; return true;
} }
@ -2311,9 +2314,13 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_FAVORITES)) ginfo.id = RS_GROUP_ID_FAVORITES ; if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_FAVORITES)) ginfo.id = RS_GROUP_ID_FAVORITES ;
if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_OTHERS )) ginfo.id = RS_GROUP_ID_OTHERS ; if(gitem->id == std::string(RS_GROUP_DEFAULT_NAME_OTHERS )) ginfo.id = RS_GROUP_ID_OTHERS ;
groupList[ginfo.id] = ginfo ; if(!ginfo.id.isNull())
{
std::cerr << "(II) Creating new group for old format local group \"" << gitem->name << "\". Id=" << ginfo.id << std::endl; groupList[ginfo.id] = ginfo ;
std::cerr << "(II) Creating new group for old format local group \"" << gitem->name << "\". Id=" << ginfo.id << std::endl;
}
else
std::cerr << "(EE) no group corresponding to old format group with ID=\"" << gitem->id << "\"" << std::endl;
continue; continue;
} }
@ -2335,6 +2342,7 @@ bool p3PeerMgrIMPL::loadList(std::list<RsItem *>& load)
info.name = gitem2->name ; info.name = gitem2->name ;
info.flag = gitem2->flag ; info.flag = gitem2->flag ;
std::cerr << "(II) Loaded group in new format. ID = " << info.id << std::endl;
groupList[info.id] = info ; groupList[info.id] = info ;
continue; continue;
@ -2483,6 +2491,8 @@ bool p3PeerMgrIMPL::addGroup(RsGroupInfo &groupInfo)
groupItem.flag &= ~RS_GROUP_FLAG_STANDARD; groupItem.flag &= ~RS_GROUP_FLAG_STANDARD;
groupList[groupInfo.id] = groupItem; groupList[groupInfo.id] = groupItem;
std::cerr << "(II) Added new group with ID " << groupInfo.id << ", name=\"" << groupInfo.name << "\"" << std::endl;
} }
RsServer::notify()->notifyListChange(NOTIFY_LIST_GROUPLIST, NOTIFY_TYPE_ADD); RsServer::notify()->notifyListChange(NOTIFY_LIST_GROUPLIST, NOTIFY_TYPE_ADD);
@ -2586,6 +2596,7 @@ bool p3PeerMgrIMPL::getGroupInfoByName(const std::string& groupName, RsGroupInfo
return true ; return true ;
} }
std::cerr << "(EE) getGroupInfoByName: no known group for name " << groupName << std::endl;
return false ; return false ;
} }
bool p3PeerMgrIMPL::getGroupInfo(const RsNodeGroupId& groupId, RsGroupInfo &groupInfo) bool p3PeerMgrIMPL::getGroupInfo(const RsNodeGroupId& groupId, RsGroupInfo &groupInfo)

View File

@ -750,7 +750,7 @@ uint32_t RsPeerConfigSerialiser::size(RsItem *i)
{ {
RsPeerStunItem *psi; RsPeerStunItem *psi;
RsPeerNetItem *pni; RsPeerNetItem *pni;
RsPeerGroupItem_deprecated *pgi; RsNodeGroupItem *pgi;
RsPeerServicePermissionItem *pri; RsPeerServicePermissionItem *pri;
RsPeerBandwidthLimitsItem *pblitem; RsPeerBandwidthLimitsItem *pblitem;
@ -762,7 +762,7 @@ uint32_t RsPeerConfigSerialiser::size(RsItem *i)
{ {
return sizeStun(psi); return sizeStun(psi);
} }
else if (NULL != (pgi = dynamic_cast<RsPeerGroupItem_deprecated *>(i))) else if (NULL != (pgi = dynamic_cast<RsNodeGroupItem*>(i)))
{ {
return sizeGroup(pgi); return sizeGroup(pgi);
} }
@ -783,7 +783,7 @@ bool RsPeerConfigSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsi
{ {
RsPeerNetItem *pni; RsPeerNetItem *pni;
RsPeerStunItem *psi; RsPeerStunItem *psi;
RsPeerGroupItem_deprecated *pgi; RsNodeGroupItem *pgi;
RsPeerServicePermissionItem *pri; RsPeerServicePermissionItem *pri;
RsPeerBandwidthLimitsItem *pblitem; RsPeerBandwidthLimitsItem *pblitem;
@ -795,7 +795,7 @@ bool RsPeerConfigSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsi
{ {
return serialiseStun(psi, data, pktsize); return serialiseStun(psi, data, pktsize);
} }
else if (NULL != (pgi = dynamic_cast<RsPeerGroupItem_deprecated *>(i))) else if (NULL != (pgi = dynamic_cast<RsNodeGroupItem*>(i)))
{ {
return serialiseGroup(pgi, data, pktsize); return serialiseGroup(pgi, data, pktsize);
} }
@ -833,8 +833,10 @@ RsItem *RsPeerConfigSerialiser::deserialise(void *data, uint32_t *pktsize)
case RS_PKT_SUBTYPE_PEER_STUN: case RS_PKT_SUBTYPE_PEER_STUN:
return deserialiseStun(data, pktsize); return deserialiseStun(data, pktsize);
case RS_PKT_SUBTYPE_PEER_GROUP_deprecated: case RS_PKT_SUBTYPE_PEER_GROUP_deprecated:
return deserialiseGroup(data, pktsize); return deserialiseGroup_deprecated(data, pktsize);
case RS_PKT_SUBTYPE_PEER_PERMISSIONS: case RS_PKT_SUBTYPE_NODE_GROUP:
return deserialiseGroup(data, pktsize);
case RS_PKT_SUBTYPE_PEER_PERMISSIONS:
return deserialisePermissions(data, pktsize); return deserialisePermissions(data, pktsize);
case RS_PKT_SUBTYPE_PEER_BANDLIMITS: case RS_PKT_SUBTYPE_PEER_BANDLIMITS:
return deserialisePeerBandwidthLimits(data, pktsize); return deserialisePeerBandwidthLimits(data, pktsize);
@ -1469,20 +1471,67 @@ std::ostream &RsPeerGroupItem_deprecated::print(std::ostream &out, uint16_t inde
return out; return out;
} }
RsPeerGroupItem_deprecated *RsPeerConfigSerialiser::deserialiseGroup_deprecated(void *data, uint32_t *size)
{
/* get the type and size */
uint32_t rstype = getRsItemId(data);
uint32_t rssize = getRsItemSize(data);
uint32_t offset = 0;
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
(RS_PKT_TYPE_PEER_CONFIG != getRsItemType(rstype)) ||
(RS_PKT_SUBTYPE_PEER_GROUP_deprecated != getRsItemSubType(rstype)))
{
return NULL; /* wrong type */
}
if (*size < rssize) /* check size */
return NULL; /* not enough data */
/* set the packet length */
*size = rssize;
bool ok = true;
RsPeerGroupItem_deprecated *item = new RsPeerGroupItem_deprecated();
item->clear();
/* skip the header */
offset += 8;
/* get mandatory parts first */
uint32_t version;
ok &= getRawUInt32(data, rssize, &offset, &version);
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_KEY, item->id);
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->name);
ok &= getRawUInt32(data, rssize, &offset, &(item->flag));
ok &= item->pgpList.GetTlv(data, rssize, &offset);
if (offset != rssize)
{
/* error */
delete item;
return NULL;
}
return item;
}
/*************************************************************************/ /*************************************************************************/
uint32_t RsPeerConfigSerialiser::sizeGroup(RsPeerGroupItem_deprecated *i) uint32_t RsPeerConfigSerialiser::sizeGroup(RsNodeGroupItem *i)
{ {
uint32_t s = 8; /* header */ uint32_t s = 8; /* header */
s += 4; /* version */ s += 4; /* version */
s += GetTlvStringSize(i->id); s += RsNodeGroupId::serial_size();
s += GetTlvStringSize(i->name); s += GetTlvStringSize(i->name);
s += 4; /* flag */ s += 4; /* flag */
s += i->pgpList.TlvSize(); s += i->pgpList.TlvSize();
return s; return s;
} }
bool RsPeerConfigSerialiser::serialiseGroup(RsPeerGroupItem_deprecated *item, void *data, uint32_t *size) bool RsPeerConfigSerialiser::serialiseGroup(RsNodeGroupItem *item, void *data, uint32_t *size)
{ {
uint32_t tlvsize = RsPeerConfigSerialiser::sizeGroup(item); uint32_t tlvsize = RsPeerConfigSerialiser::sizeGroup(item);
uint32_t offset = 0; uint32_t offset = 0;
@ -1508,7 +1557,7 @@ bool RsPeerConfigSerialiser::serialiseGroup(RsPeerGroupItem_deprecated *item, vo
/* add mandatory parts first */ /* add mandatory parts first */
ok &= setRawUInt32(data, tlvsize, &offset, 0); ok &= setRawUInt32(data, tlvsize, &offset, 0);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_KEY, item->id); ok &= item->id.serialise(data, tlvsize, offset);
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, item->name); ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_NAME, item->name);
ok &= setRawUInt32(data, tlvsize, &offset, item->flag); ok &= setRawUInt32(data, tlvsize, &offset, item->flag);
ok &= item->pgpList.SetTlv(data, tlvsize, &offset); ok &= item->pgpList.SetTlv(data, tlvsize, &offset);
@ -1524,7 +1573,7 @@ bool RsPeerConfigSerialiser::serialiseGroup(RsPeerGroupItem_deprecated *item, vo
return ok; return ok;
} }
RsPeerGroupItem_deprecated *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t *size) RsNodeGroupItem *RsPeerConfigSerialiser::deserialiseGroup(void *data, uint32_t *size)
{ {
/* get the type and size */ /* get the type and size */
uint32_t rstype = getRsItemId(data); uint32_t rstype = getRsItemId(data);
@ -1535,7 +1584,7 @@ RsPeerGroupItem_deprecated *RsPeerConfigSerialiser::deserialiseGroup(void *data,
if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) || if ((RS_PKT_VERSION1 != getRsItemVersion(rstype)) ||
(RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) || (RS_PKT_CLASS_CONFIG != getRsItemClass(rstype)) ||
(RS_PKT_TYPE_PEER_CONFIG != getRsItemType(rstype)) || (RS_PKT_TYPE_PEER_CONFIG != getRsItemType(rstype)) ||
(RS_PKT_SUBTYPE_PEER_GROUP_deprecated != getRsItemSubType(rstype))) (RS_PKT_SUBTYPE_NODE_GROUP != getRsItemSubType(rstype)))
{ {
return NULL; /* wrong type */ return NULL; /* wrong type */
} }
@ -1548,7 +1597,7 @@ RsPeerGroupItem_deprecated *RsPeerConfigSerialiser::deserialiseGroup(void *data,
bool ok = true; bool ok = true;
RsPeerGroupItem_deprecated *item = new RsPeerGroupItem_deprecated(); RsNodeGroupItem *item = new RsNodeGroupItem();
item->clear(); item->clear();
/* skip the header */ /* skip the header */
@ -1557,7 +1606,7 @@ RsPeerGroupItem_deprecated *RsPeerConfigSerialiser::deserialiseGroup(void *data,
/* get mandatory parts first */ /* get mandatory parts first */
uint32_t version; uint32_t version;
ok &= getRawUInt32(data, rssize, &offset, &version); ok &= getRawUInt32(data, rssize, &offset, &version);
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_KEY, item->id); ok &= item->id.deserialise(data, rssize, offset);
ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->name); ok &= GetTlvString(data, rssize, &offset, TLV_TYPE_STR_NAME, item->name);
ok &= getRawUInt32(data, rssize, &offset, &(item->flag)); ok &= getRawUInt32(data, rssize, &offset, &(item->flag));
ok &= item->pgpList.GetTlv(data, rssize, &offset); ok &= item->pgpList.GetTlv(data, rssize, &offset);

View File

@ -222,9 +222,10 @@ virtual uint32_t sizeStun(RsPeerStunItem *);
virtual bool serialiseStun (RsPeerStunItem *item, void *data, uint32_t *size); virtual bool serialiseStun (RsPeerStunItem *item, void *data, uint32_t *size);
virtual RsPeerStunItem * deserialiseStun(void *data, uint32_t *size); virtual RsPeerStunItem * deserialiseStun(void *data, uint32_t *size);
virtual uint32_t sizeGroup(RsPeerGroupItem_deprecated *); virtual uint32_t sizeGroup(RsNodeGroupItem *);
virtual bool serialiseGroup (RsPeerGroupItem_deprecated *item, void *data, uint32_t *size); virtual bool serialiseGroup (RsNodeGroupItem *item, void *data, uint32_t *size);
virtual RsPeerGroupItem_deprecated * deserialiseGroup(void *data, uint32_t *size); virtual RsNodeGroupItem *deserialiseGroup(void *data, uint32_t *size);
virtual RsPeerGroupItem_deprecated * deserialiseGroup_deprecated(void *data, uint32_t *size);
virtual uint32_t sizePeerBandwidthLimits(RsPeerBandwidthLimitsItem *); virtual uint32_t sizePeerBandwidthLimits(RsPeerBandwidthLimitsItem *);
virtual bool serialisePeerBandwidthLimits (RsPeerBandwidthLimitsItem *item, void *data, uint32_t *size); virtual bool serialisePeerBandwidthLimits (RsPeerBandwidthLimitsItem *item, void *data, uint32_t *size);

View File

@ -217,7 +217,17 @@ void FriendList::processSettings(bool load)
int arrayIndex = Settings->beginReadArray("Groups"); int arrayIndex = Settings->beginReadArray("Groups");
for (int index = 0; index < arrayIndex; ++index) { for (int index = 0; index < arrayIndex; ++index) {
Settings->setArrayIndex(index); Settings->setArrayIndex(index);
addGroupToExpand(RsNodeGroupId(Settings->value("open").toString().toStdString()));
std::string gids = Settings->value("open").toString().toStdString();
RsGroupInfo ginfo ;
if(rsPeers->getGroupInfoByName(gids,ginfo)) // backward compatibility
addGroupToExpand(ginfo.id) ;
else if(rsPeers->getGroupInfo(RsNodeGroupId(gids),ginfo)) // backward compatibility
addGroupToExpand(ginfo.id) ;
else
std::cerr << "(EE) Cannot find group info for openned group \"" << gids << "\"" << std::endl;
} }
Settings->endArray(); Settings->endArray();
} else { } else {

View File

@ -51,7 +51,7 @@ const QString GroupDefs::name(const RsGroupInfo &groupInfo)
return qApp->translate("GroupDefs", "Favorites"); return qApp->translate("GroupDefs", "Favorites");
} }
std::cerr << "GroupDefs::name: Unknown group id requested " << groupInfo.id; std::cerr << "GroupDefs::name: Unknown group id requested " << groupInfo.id << std::endl;
return ""; return "";
} }

View File

@ -45,6 +45,11 @@ CreateGroup::CreateGroup(const RsNodeGroupId &groupId, QWidget *parent)
mGroupId = groupId; mGroupId = groupId;
if(!mGroupId.isNull())
ui.groupId_LE->setText(QString::fromStdString(mGroupId.toStdString())) ;
else
ui.groupId_LE->setText(tr("To be defined")) ;
/* Initialize friends list */ /* Initialize friends list */
ui.friendList->setHeaderText(tr("Friends")); ui.friendList->setHeaderText(tr("Friends"));
ui.friendList->setModus(FriendSelectionWidget::MODUS_CHECK); ui.friendList->setModus(FriendSelectionWidget::MODUS_CHECK);
@ -104,9 +109,9 @@ CreateGroup::~CreateGroup()
void CreateGroup::groupNameChanged(QString text) void CreateGroup::groupNameChanged(QString text)
{ {
if (text.isEmpty() || mUsedGroupNames.contains(misc::removeNewLine(text))) { if (text.isEmpty() || mUsedGroupNames.contains(misc::removeNewLine(text))) {
ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
} else { } else {
ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
} }
} }

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>386</width> <width>575</width>
<height>298</height> <height>485</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -23,9 +23,6 @@
<property name="margin"> <property name="margin">
<number>0</number> <number>0</number>
</property> </property>
<item row="0" column="0">
<widget class="HeaderFrame" name="headerFrame"/>
</item>
<item row="1" column="0"> <item row="1" column="0">
<widget class="QFrame" name="frame"> <widget class="QFrame" name="frame">
<property name="frameShape"> <property name="frameShape">
@ -36,27 +33,35 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<layout class="QHBoxLayout" name="groupLayout"> <layout class="QGridLayout" name="gridLayout">
<property name="spacing"> <item row="0" column="0">
<number>6</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="groupLabel"> <widget class="QLabel" name="groupLabel">
<property name="text"> <property name="text">
<string>Group Name</string> <string>Group Name:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="0" column="1">
<widget class="QLineEdit" name="groupName"> <widget class="QLineEdit" name="groupName">
<property name="toolTip"> <property name="toolTip">
<string>Enter a name for your group</string> <string>Enter a name for your group</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0">
<widget class="QLabel" name="groupId_LB">
<property name="text">
<string>Group ID:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="groupId_LE">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>
@ -79,6 +84,9 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="0" column="0">
<widget class="HeaderFrame" name="headerFrame"/>
</item>
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>