Peer info
git-svn-id: svn://db.shs.com.ru/pip@29 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -201,13 +201,7 @@ public:
|
|||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
PIDeque<T> & reserve(size_t new_size) {
|
PIDeque<T> & reserve(size_t new_size) {if (new_size <= pid_rsize) return *this; size_t os = pid_size; alloc(new_size, true); pid_size = os; return *this;}
|
||||||
if (new_size <= pid_rsize) return *this;
|
|
||||||
size_t os = pid_size;
|
|
||||||
alloc(new_size, true);
|
|
||||||
pid_size = os;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
PIDeque<T> & insert(size_t index, const T & v = T()) {
|
PIDeque<T> & insert(size_t index, const T & v = T()) {
|
||||||
bool dir = pid_rsize <= 2 ? true : (index >= pid_rsize / 2 ? true : false);
|
bool dir = pid_rsize <= 2 ? true : (index >= pid_rsize / 2 ? true : false);
|
||||||
@@ -216,10 +210,11 @@ public:
|
|||||||
alloc(pid_size + 1, true);
|
alloc(pid_size + 1, true);
|
||||||
if (index < pid_size - 1) {
|
if (index < pid_size - 1) {
|
||||||
size_t os = pid_size - index - 1;
|
size_t os = pid_size - index - 1;
|
||||||
memmove(&(pid_data[index + pid_start + 1]), &(pid_data[index + pid_start]), os * sizeof(T));
|
memmove(&(pid_data[pid_start + index + 1]), &(pid_data[pid_start + index]), os * sizeof(T));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
alloc(pid_size + 1, false, -1);
|
pid_start--;
|
||||||
|
alloc(pid_size + 1, false);
|
||||||
//piCout << "insert front" << pid_size << pid_rsize << pid_start << "!<";
|
//piCout << "insert front" << pid_size << pid_rsize << pid_start << "!<";
|
||||||
if (index > 0)
|
if (index > 0)
|
||||||
memmove(&(pid_data[pid_start]), &(pid_data[pid_start + 1]), index * sizeof(T));
|
memmove(&(pid_data[pid_start]), &(pid_data[pid_start + 1]), index * sizeof(T));
|
||||||
@@ -231,22 +226,20 @@ public:
|
|||||||
PIDeque<T> & insert(size_t index, const PIDeque<T> & other) {
|
PIDeque<T> & insert(size_t index, const PIDeque<T> & other) {
|
||||||
if (other.isEmpty()) return *this;
|
if (other.isEmpty()) return *this;
|
||||||
bool dir = pid_rsize <= 2 ? true : (index >= pid_rsize / 2 ? true : false);
|
bool dir = pid_rsize <= 2 ? true : (index >= pid_rsize / 2 ? true : false);
|
||||||
//piCout << this << "insert" << dir << index << pid_size << pid_rsize << pid_start << " <- " << other.size() << "!<";
|
//piCout << "insert" << dir << index << pid_size << pid_rsize << pid_start << "!<";
|
||||||
if (dir) {
|
if (dir) {
|
||||||
ssize_t os = pid_size - index;
|
ssize_t os = pid_size - index;
|
||||||
alloc(pid_size + other.pid_size, true);
|
alloc(pid_size + other.pid_size, true);
|
||||||
if (os > 0)
|
if (os > 0)
|
||||||
memmove(&(pid_data[index + pid_start + other.pid_size]), &(pid_data[index + pid_start]), os * sizeof(T));
|
memmove(&(pid_data[pid_start + index + other.pid_size]), &(pid_data[pid_start + index]), os * sizeof(T));
|
||||||
} else {
|
} else {
|
||||||
//if (pid_start < other.pid_size) pid_start = 0;
|
pid_start -= other.pid_size;
|
||||||
//piCout << this << " insert offseted start ba" << pid_start << pid_size << pid_rsize;
|
alloc(pid_size + other.pid_size, false);
|
||||||
alloc(pid_size + other.pid_size, false, -other.pid_size);
|
//piCout << "insert front" << pid_size << pid_rsize << pid_start << "!<";
|
||||||
//piCout << this << " insert offseted start aa" << pid_start << pid_size << pid_rsize;
|
|
||||||
//piCout << this << " insert front" << pid_size << pid_rsize << pid_start << "!<";
|
|
||||||
if (index > 0)
|
if (index > 0)
|
||||||
memmove(&(pid_data[pid_start]), &(pid_data[pid_start + other.pid_size]), index * sizeof(T));
|
memmove(&(pid_data[pid_start]), &(pid_data[pid_start + other.pid_size]), index * sizeof(T));
|
||||||
}
|
}
|
||||||
//piCout << this << "insert" << pid_start << index << (pid_start + ssize_t(index)) << pid_size << ">!";
|
//piCout << "insert" << pid_start << index << (pid_start + ssize_t(index)) << pid_size << ">!";
|
||||||
newT(pid_data + pid_start + index, other.pid_data + other.pid_start, other.pid_size);
|
newT(pid_data + pid_start + index, other.pid_data + other.pid_start, other.pid_size);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -258,10 +251,10 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
size_t os = pid_size - index - count;
|
size_t os = pid_size - index - count;
|
||||||
deleteT(&(pid_data[index + pid_start]), count);
|
deleteT(&(pid_data[pid_start + index]), count);
|
||||||
if (os <= index) {
|
if (os <= index) {
|
||||||
//if (true) {
|
//if (true) {
|
||||||
if (os > 0) memmove(&(pid_data[index + pid_start]), &(pid_data[index + pid_start + count]), os * sizeof(T));
|
if (os > 0) memmove(&(pid_data[pid_start + index]), &(pid_data[pid_start + index + count]), os * sizeof(T));
|
||||||
} else {
|
} else {
|
||||||
if (index > 0) memmove(&(pid_data[pid_start + count]), &(pid_data[pid_start]), index * sizeof(T));
|
if (index > 0) memmove(&(pid_data[pid_start + count]), &(pid_data[pid_start]), index * sizeof(T));
|
||||||
pid_start += count;
|
pid_start += count;
|
||||||
@@ -334,11 +327,11 @@ private:
|
|||||||
elementNew(dst + i, src[i]);
|
elementNew(dst + i, src[i]);
|
||||||
}
|
}
|
||||||
inline T * newRaw(size_t s) {
|
inline T * newRaw(size_t s) {
|
||||||
//std::cout << std::dec << " ![("<<this<<")newRaw " << s << " elements ... <" << std::endl;
|
//cout << std::dec << " ![("<<this<<")newRaw " << s << " elements ... <\n" << endl;
|
||||||
//uchar * ret = new uchar[s * sizeof(T)];
|
//uchar * ret = new uchar[s * sizeof(T)];
|
||||||
uchar * ret = (uchar*)(malloc(s * sizeof(T)));//new uchar[];
|
uchar * ret = (uchar*)(malloc(s * sizeof(T)));//new uchar[];
|
||||||
//zeroRaw((T*)ret, s);
|
//zeroRaw((T*)ret, s);
|
||||||
//std::cout << std::hex << " > (new 0x" << (llong)ret << ") ok]!" << std::endl;
|
//cout << std::hex << " > (new 0x" << (llong)ret << ") ok]!" << endl;
|
||||||
return (T*)ret;
|
return (T*)ret;
|
||||||
}
|
}
|
||||||
/*void reallocRawTemp(size_t s) {
|
/*void reallocRawTemp(size_t s) {
|
||||||
@@ -346,7 +339,7 @@ private:
|
|||||||
else pid_tdata = (T*)(realloc(pid_tdata, s * sizeof(T)));
|
else pid_tdata = (T*)(realloc(pid_tdata, s * sizeof(T)));
|
||||||
}*/
|
}*/
|
||||||
inline void deleteT(T * d, size_t sz) {
|
inline void deleteT(T * d, size_t sz) {
|
||||||
//std::cout << " ~[("<<this<<")deleteT " << std::dec << sz << " elements " << " start " << pid_start << std::hex << " 0x" << (llong)d << " ... <" << std::endl;
|
//cout << " ~[("<<this<<")deleteT " << std::dec << sz << " elements " << std::hex << "0x" << (llong)d << " ... <\n" << endl;
|
||||||
if ((uchar*)d != 0) {
|
if ((uchar*)d != 0) {
|
||||||
for (size_t i = 0; i < sz; ++i)
|
for (size_t i = 0; i < sz; ++i)
|
||||||
elementDelete(d[i]);
|
elementDelete(d[i]);
|
||||||
@@ -369,7 +362,7 @@ private:
|
|||||||
inline void elementDelete(T & from) {from.~T();}
|
inline void elementDelete(T & from) {from.~T();}
|
||||||
void dealloc() {deleteRaw(pid_data);}
|
void dealloc() {deleteRaw(pid_data);}
|
||||||
inline void checkMove(bool direction) {
|
inline void checkMove(bool direction) {
|
||||||
if (pid_size >= 4 && pid_size < pid_rsize / 6) {
|
if (pid_size >= 4 && pid_size < pid_rsize / 4) {
|
||||||
/*if (direction) {
|
/*if (direction) {
|
||||||
if (pid_start >= 4 && pid_start > pid_size + pid_size && pid_start > pid_rsize / 2) {
|
if (pid_start >= 4 && pid_start > pid_size + pid_size && pid_start > pid_rsize / 2) {
|
||||||
piCout << (int)this << "checkMove" << direction << pid_start << (int)pid_data << pid_rsize << pid_size;
|
piCout << (int)this << "checkMove" << direction << pid_start << (int)pid_data << pid_rsize << pid_size;
|
||||||
@@ -385,18 +378,16 @@ private:
|
|||||||
pid_start = ssize_t(pid_rsize) - pid_size - pid_size;
|
pid_start = ssize_t(pid_rsize) - pid_size - pid_size;
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
//printf("(%p) check move st=%d sz=%d rs=%d\n", this, pid_start, pid_size, pid_rsize);
|
|
||||||
if (pid_start < pid_size + pid_size || pid_start > pid_rsize - pid_size - pid_size) {
|
if (pid_start < pid_size + pid_size || pid_start > pid_rsize - pid_size - pid_size) {
|
||||||
ssize_t ns = (pid_rsize - pid_size) / 2;
|
size_t ns = (pid_rsize - pid_size) / 2;
|
||||||
if (pid_start != ns) {
|
if (pid_start != ns) {
|
||||||
//printf("(%p) move %d -> %d\n", this, pid_start, ns);
|
|
||||||
memmove(pid_data + ns, pid_data + pid_start, pid_size * sizeof(T));
|
memmove(pid_data + ns, pid_data + pid_start, pid_size * sizeof(T));
|
||||||
pid_start = ns;
|
pid_start = ns;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inline void alloc(size_t new_size, bool direction, ssize_t start_offset = 0) { // direction == true -> alloc forward
|
inline void alloc(size_t new_size, bool direction) { // direction == true -> alloc forward
|
||||||
if (direction) {
|
if (direction) {
|
||||||
if (pid_start + new_size <= pid_rsize) {
|
if (pid_start + new_size <= pid_rsize) {
|
||||||
pid_size = new_size;
|
pid_size = new_size;
|
||||||
@@ -406,46 +397,42 @@ private:
|
|||||||
pid_size = new_size;
|
pid_size = new_size;
|
||||||
size_t as = asize(pid_start + new_size);
|
size_t as = asize(pid_start + new_size);
|
||||||
if (as != pid_rsize) {
|
if (as != pid_rsize) {
|
||||||
//printf("(%p) realloc %d -> %d (%p)\n", this, pid_rsize, as, pid_data);
|
|
||||||
pid_data = (T*)(realloc(pid_data, as*sizeof(T)));
|
pid_data = (T*)(realloc(pid_data, as*sizeof(T)));
|
||||||
pid_rsize = as;
|
pid_rsize = as;
|
||||||
//printf("(%p) realloc done (%p)\n", this, pid_data);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
size_t as;
|
size_t as = asize(piMax<ssize_t>(new_size, pid_rsize) - pid_start);
|
||||||
//piCout << "INS ba" << *this;
|
//piCout << "alloc" << new_size << pid_size << pid_rsize << as << pid_start;
|
||||||
if (pid_start + start_offset < 0)
|
if (pid_start >= 0 && as <= pid_rsize) {
|
||||||
as = asize(pid_rsize - start_offset);
|
pid_size = new_size;
|
||||||
else as = pid_rsize;
|
checkMove(direction);
|
||||||
//printf("%X alloc %d %d\n", this, pid_rsize, start_offset);
|
return;
|
||||||
//printf("%X alloc %d %d %d %d %d %d\n", this, new_size, pid_size, pid_rsize, as, pid_start, start_offset);
|
}
|
||||||
|
size_t os = pid_size;
|
||||||
|
pid_size = new_size;
|
||||||
if (as > pid_rsize) {
|
if (as > pid_rsize) {
|
||||||
//printf("%X alloc new size %d\n", this, as);
|
//piCout << "alloc new size" << as;
|
||||||
//cout << std::hex << " ![("<<this<<")realloc " << pid_data << " data ... <\n" << endl;
|
//cout << std::hex << " ![("<<this<<")realloc " << pid_data << " data ... <\n" << endl;
|
||||||
T * td = newRaw(as);
|
T * td = newRaw(as);
|
||||||
ssize_t ns = pid_start + as - pid_rsize;
|
//piCout << "pid_start" << pid_start << (pid_start + ssize_t(as) - os);
|
||||||
//printf("%X pid_start ost=%d ors=%d nst=%d nrs=%d\n", this, pid_start, pid_rsize, ns, as);
|
ssize_t ost = pid_start, ns = 0;
|
||||||
if (pid_rsize > 0 && pid_data != 0) {
|
if (ost < 0) {ns -= ost; ost = 0;}
|
||||||
//printf("%X copy from %p + %d to %p + %d %d el\n", this, pid_data, pid_start, td, ns, pid_size);
|
pid_start += ssize_t(as) - os;
|
||||||
memcpy(td + ns, pid_data + pid_start, pid_size * sizeof(T));
|
if (os > 0 && pid_data != 0) {
|
||||||
|
memcpy(td + pid_start + ns, pid_data + ost, os * sizeof(T));
|
||||||
deleteRaw(pid_data);
|
deleteRaw(pid_data);
|
||||||
}
|
}
|
||||||
pid_data = td;
|
pid_data = td;
|
||||||
pid_rsize = as;
|
pid_rsize = as;
|
||||||
pid_start = ns;
|
|
||||||
//piCout << "INS aa" << *this;
|
|
||||||
}
|
}
|
||||||
pid_start += start_offset;
|
|
||||||
pid_size = new_size;
|
|
||||||
checkMove(direction);
|
|
||||||
}
|
}
|
||||||
//checkMove(direction);
|
//checkMove(direction);
|
||||||
//printf("%X alloc new start %d\n", this, pid_start);
|
//piCout << "alloc new start" << pid_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
T * pid_data;
|
T * pid_data;
|
||||||
volatile size_t pid_size, pid_rsize;
|
volatile size_t pid_size, pid_rsize;
|
||||||
volatile ssize_t pid_start;
|
volatile size_t pid_start;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define __PIDEQUE_SIMPLE_TYPE__(T) \
|
#define __PIDEQUE_SIMPLE_TYPE__(T) \
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ public:
|
|||||||
PIString name;
|
PIString name;
|
||||||
PIVector<Address> addresses;
|
PIVector<Address> addresses;
|
||||||
int dist;
|
int dist;
|
||||||
|
PIStringList neighbours;
|
||||||
|
|
||||||
bool isNeighbour() const {return dist == 0;}
|
bool isNeighbour() const {return dist == 0;}
|
||||||
int ping() const;
|
int ping() const;
|
||||||
@@ -80,7 +81,6 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
PIString nearest_address;
|
PIString nearest_address;
|
||||||
PIStringList neighbours;
|
|
||||||
int sync, cnt, trace;
|
int sync, cnt, trace;
|
||||||
bool was_update;
|
bool was_update;
|
||||||
PISystemTime time;
|
PISystemTime time;
|
||||||
|
|||||||
@@ -141,6 +141,7 @@ public:
|
|||||||
if (cur_peer >= 0 && cur_peer < daemon_.allPeers().size_s()) pi = daemon_.allPeers()[cur_peer];
|
if (cur_peer >= 0 && cur_peer < daemon_.allPeers().size_s()) pi = daemon_.allPeers()[cur_peer];
|
||||||
peerinfo_tl->content << TileSimple::Row("Name: " + pi.name, CellFormat());
|
peerinfo_tl->content << TileSimple::Row("Name: " + pi.name, CellFormat());
|
||||||
peerinfo_tl->content << TileSimple::Row("Addreses: " + PIString::fromNumber(pi.addresses.size()), CellFormat());
|
peerinfo_tl->content << TileSimple::Row("Addreses: " + PIString::fromNumber(pi.addresses.size()), CellFormat());
|
||||||
|
peerinfo_tl->content << TileSimple::Row("Neighbours: " + pi.neighbours.join(", "), CellFormat());
|
||||||
piForeachC(PIPeer::PeerInfo::Address &a , pi.addresses)
|
piForeachC(PIPeer::PeerInfo::Address &a , pi.addresses)
|
||||||
addrs_tl->content << TileList::Row(a.address + " | " + a.netmask +
|
addrs_tl->content << TileList::Row(a.address + " | " + a.netmask +
|
||||||
" | " + PIString::fromNumber(a.ping) +
|
" | " + PIString::fromNumber(a.ping) +
|
||||||
@@ -150,7 +151,7 @@ public:
|
|||||||
PIStringList peermap;
|
PIStringList peermap;
|
||||||
piForeachC(PeerPair &p , daemon_._peerMap()) {
|
piForeachC(PeerPair &p , daemon_._peerMap()) {
|
||||||
PIString s = p.first + " | ";
|
PIString s = p.first + " | ";
|
||||||
piForeachC(PIPeer::PeerInfo * pp, p.second) s += "->" + pp->name;
|
piForeachCR(PIPeer::PeerInfo * pp, p.second) s += " -> " + pp->name;
|
||||||
peermap << s;
|
peermap << s;
|
||||||
}
|
}
|
||||||
piForeachC(PIString &s , peermap)
|
piForeachC(PIString &s , peermap)
|
||||||
|
|||||||
Reference in New Issue
Block a user