• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision754f64d48512602cca64ba9a11c75bba1c548eee (tree)
Time2008-01-22 20:18:29
Authoreru <eru01@user...>
Commitereru

Log Message

バグ修正コード(VPdiff_27_20080120)マージ
バグ修正コード(VPdiff_27_20080120)をマージ

Change Summary

Incremental Difference

--- a/PeerCast.root/PeerCast/core/common/channel.cpp
+++ b/PeerCast.root/PeerCast/core/common/channel.cpp
@@ -608,6 +608,10 @@ void PeercastSource::stream(Channel *ch)
608608 bool next_yp = false;
609609 bool tracker_check = (ch->trackerHit.host.ip != 0);
610610 int connFailCnt = 0;
611+ int keepDownstreamTime = 7;
612+
613+ if (isIndexTxt(&ch->info))
614+ keepDownstreamTime = 30;
611615
612616 ch->lastStopTime = 0;
613617 ch->bumped = false;
@@ -720,7 +724,9 @@ void PeercastSource::stream(Channel *ch)
720724
721725 chanMgr->hitlistlock.off();
722726
723- if (servMgr->keepDownstreams && ch->lastStopTime && ch->lastStopTime < sys->getTime() - 7) {
727+ if (servMgr->keepDownstreams && ch->lastStopTime
728+ && ch->lastStopTime < sys->getTime() - keepDownstreamTime)
729+ {
724730 ch->lastStopTime = 0;
725731 LOG_DEBUG("------------ disconnect all downstreams");
726732 ChanPacket pack;
@@ -902,7 +908,7 @@ yp0:
902908 ch->trackerHit.lastContact = ctime - 30 + (rand() % 30);
903909
904910 // broadcast source host
905- if (!error && ch->sourceHost.host.ip) { // if closed normally
911+ if (!got503 && !error && ch->sourceHost.host.ip) { // if closed normally
906912 ChanPacket pack;
907913 MemoryStream mem(pack.data,sizeof(pack.data));
908914 AtomStream atom(mem);
@@ -916,7 +922,7 @@ yp0:
916922 }
917923
918924 // broadcast quit to any connected downstream servents
919- if (!servMgr->keepDownstreams || (ch->sourceHost.tracker && !got503) || !error) {
925+ if (!servMgr->keepDownstreams || !got503 && (ch->sourceHost.tracker || !error)) {
920926 ChanPacket pack;
921927 MemoryStream mem(pack.data,sizeof(pack.data));
922928 AtomStream atom(mem);
@@ -1385,6 +1391,17 @@ bool ChannelStream::getStatus(Channel *ch,ChanPacket &pack)
13851391 {
13861392 unsigned int ctime = sys->getTime();
13871393
1394+ if ((ch->isPlaying() == isPlaying)){
1395+ if ((ctime-lastUpdate) < 10){
1396+ return false;
1397+ }
1398+
1399+ if ((ctime-lastCheckTime) < 5){
1400+ return false;
1401+ }
1402+ lastCheckTime = ctime;
1403+ }
1404+
13881405 ChanHitList *chl = chanMgr->findHitListByID(ch->info.id);
13891406
13901407 if (!chl)
@@ -1419,17 +1436,6 @@ bool ChannelStream::getStatus(Channel *ch,ChanPacket &pack)
14191436 int newLocalListeners = ch->localListeners();
14201437 int newLocalRelays = ch->localRelays();
14211438
1422- if ((ch->isPlaying() == isPlaying)){
1423- if ((ctime-lastUpdate) < 10){
1424- return false;
1425- }
1426-
1427- if ((ctime-lastCheckTime) < 10){
1428- return false;
1429- }
1430- lastCheckTime = ctime;
1431- }
1432-
14331439 unsigned int oldp = ch->rawData.getOldestPos();
14341440 unsigned int newp = ch->rawData.getLatestPos();
14351441
@@ -1611,9 +1617,11 @@ int Channel::readStream(Stream &in,ChannelStream *source)
16111617 setStatus(Channel::S_RECEIVING);
16121618 bumped = false;
16131619 }
1614- source->updateStatus(this);
1620+ //source->updateStatus(this);
16151621 }
16161622 }
1623+ if (rawData.lastWriteTime > 0 || rawData.lastSkipTime > 0)
1624+ source->updateStatus(this);
16171625
16181626 unsigned int t = sys->getTime();
16191627 if (t != ptime) {
@@ -1886,9 +1894,11 @@ bool ChanPacketBuffer::findPacket(unsigned int spos, ChanPacket &pack)
18861894 lock.on();
18871895
18881896 unsigned int bound = packets[0].len * ChanPacketBuffer::MAX_PACKETS * 2; // max packets to wait
1889- unsigned int fpos = getStreamPos(firstPos);
1890- unsigned int lpos = getStreamPos(lastPos);
1891- if (spos < fpos && (fpos < lpos || spos > lpos + bound))
1897+ unsigned int fpos = getFirstDataPos();
1898+ unsigned int lpos = getLatestPos();
1899+ if ((spos < fpos && fpos <= lpos && spos != getStreamPosEnd(lastPos)) // --s-----f---l--
1900+ || (spos < fpos && lpos < fpos && spos > lpos + bound) // -l-------s--f--
1901+ || (spos > lpos && lpos >= fpos && spos - lpos > bound)) // --f---l------s-
18921902 spos = fpos;
18931903
18941904
@@ -1917,6 +1927,18 @@ unsigned int ChanPacketBuffer::getLatestPos()
19171927
19181928 }
19191929 // -----------------------------------
1930+unsigned int ChanPacketBuffer::getFirstDataPos()
1931+{
1932+ if (!writePos)
1933+ return 0;
1934+ for(unsigned int i=firstPos; i<=lastPos; i++)
1935+ {
1936+ if (packets[i%MAX_PACKETS].type == ChanPacket::T_DATA)
1937+ return packets[i%MAX_PACKETS].pos;
1938+ }
1939+ return 0;
1940+}
1941+// -----------------------------------
19201942 unsigned int ChanPacketBuffer::getOldestPos()
19211943 {
19221944 if (!writePos)
@@ -3897,6 +3919,15 @@ int ChanHitList::pickSourceHits(ChanHitSearch &chs)
38973919 return 0;
38983920 }
38993921
3922+// -----------------------------------
3923+unsigned int ChanHitList::getSeq()
3924+{
3925+ unsigned int seq;
3926+ seqLock.on();
3927+ seq = riSequence = (riSequence + 1) & 0xffffff;
3928+ seqLock.off();
3929+ return seq;
3930+}
39003931
39013932 // -----------------------------------
39023933 const char *ChanInfo::getTypeStr(TYPE t)
@@ -4703,40 +4734,18 @@ int ChanHitSearch::getRelayHost(Host host1, Host host2, GnuID exID, ChanHitList
47034734 int index = 0;
47044735 int prob;
47054736 int rnd;
4706- static int base = 0x400;
4737+ int base = 0x400;
47074738 ChanHit tmpHit[MAX_RESULTS];
4708- static WLock seqLock;
4709- static unsigned int riSequence = 0;
47104739
47114740 //srand(seed);
47124741 //seed += 11;
47134742
4714- unsigned int seq;
4715- seqLock.on();
4716- seq = riSequence++;
4717- riSequence &= 0xffffff;
4718- seqLock.off();
4719-
4720- Servent *s = servMgr->servents;
4721- while (s) {
4722- if (s->serventHit.rhost[0].port && s->type == Servent::T_RELAY
4723- && s->chanID.isSame(chl->info.id)) {
4724- int i = index % MAX_RESULTS;
4725- if (index < MAX_RESULTS
4726- || tmpHit[i].lastSendSeq > s->serventHit.lastSendSeq) {
4727- s->serventHit.lastSendSeq = seq;
4728- tmpHit[i] = s->serventHit;
4729- tmpHit[i].host = s->serventHit.rhost[0];
4730- index++;
4731- }
4732- }
4733- s = s->next;
4734- }
4743+ unsigned int seq = chl->getSeq();
47354744
47364745 ChanHit *hit = chl->hit;
47374746
47384747 while(hit){
4739- if (hit->host.ip && !hit->dead){
4748+ if (hit->rhost[0].ip && !hit->dead) {
47404749 if (
47414750 (!exID.isSame(hit->sessionID))
47424751 // && (hit->relay)
@@ -4764,7 +4773,6 @@ int ChanHitSearch::getRelayHost(Host host1, Host host2, GnuID exID, ChanHitList
47644773 //rnd = (float)rand() / (float)RAND_MAX;
47654774 rnd = rand() % base;
47664775 if (hit->numHops == 1){
4767-#if 0
47684776 if (tmpHit[index % MAX_RESULTS].numHops == 1){
47694777 if (rnd < prob){
47704778 tmpHit[index % MAX_RESULTS] = *hit;
@@ -4776,9 +4784,8 @@ int ChanHitSearch::getRelayHost(Host host1, Host host2, GnuID exID, ChanHitList
47764784 tmpHit[index % MAX_RESULTS].host = hit->rhost[0];
47774785 index++;
47784786 }
4779-#endif
47804787 } else {
4781- if ((tmpHit[index % MAX_RESULTS].numHops != 1) && (rnd < prob) || rnd == 0){
4788+ if ((tmpHit[index % MAX_RESULTS].numHops != 1) && (rnd < prob)){
47824789 tmpHit[index % MAX_RESULTS] = *hit;
47834790 tmpHit[index % MAX_RESULTS].host = hit->rhost[0];
47844791 index++;
@@ -4822,15 +4829,9 @@ int ChanHitSearch::getRelayHost(Host host1, Host host2, GnuID exID, ChanHitList
48224829 best[use[i]] = tmpHit[i];
48234830 }*/
48244831
4825- int use[MAX_RESULTS];
4826- int i;
4827- for (i = 0; i < cnt; i++) {
4828- use[i] = (i + seq) % cnt;
4829- }
4830-
4831- for (i = 0; i < cnt; i++){
4832+ for (int i = 0; i < cnt; i++){
48324833 // LOG_DEBUG("%d", use[i]);
4833- best[use[i]] = tmpHit[i];
4834+ best[(i + seq) % cnt] = tmpHit[i];
48344835 }
48354836 // for (i = 0; i < cnt; i++){
48364837 // char tmp[50];
--- a/PeerCast.root/PeerCast/core/common/channel.h
+++ b/PeerCast.root/PeerCast/core/common/channel.h
@@ -249,13 +249,16 @@ public:
249249 int getTotalRelays();
250250 int getTotalFirewalled();
251251
252+ unsigned int getSeq();
253+
252254 bool used;
253255 ChanInfo info;
254256 ChanHit *hit;
255257 unsigned int lastHitTime;
256258 ChanHitList *next;
257259
258-
260+ WLock seqLock;
261+ unsigned int riSequence;
259262 };
260263 // ----------------------------------
261264 class ChanHitSearch
--- a/PeerCast.root/PeerCast/core/common/cstream.h
+++ b/PeerCast.root/PeerCast/core/common/cstream.h
@@ -187,6 +187,7 @@ public:
187187
188188 int numPending() {return writePos-readPos;}
189189
190+ unsigned int getFirstDataPos();
190191 unsigned int getLatestPos();
191192 unsigned int getOldestPos();
192193 unsigned int findOldestPos(unsigned int);
--- a/PeerCast.root/PeerCast/core/common/pcp.cpp
+++ b/PeerCast.root/PeerCast/core/common/pcp.cpp
@@ -547,7 +547,7 @@ void PCPStream::readHostAtoms(AtomStream &atom, int numc, BroadcastState &bcs, C
547547 if (sv && sv->getHost().ip == hit.host.ip){
548548 // LOG_DEBUG("set servent's waitPort = %d", hit.host.port);
549549 sv->waitPort = hit.host.port;
550- hit.lastSendSeq = sv->serventHit.lastSendSeq;
550+ //hit.lastSendSeq = sv->serventHit.lastSendSeq;
551551 sv->serventHit = hit;
552552 }
553553 }
@@ -761,7 +761,7 @@ int PCPStream::readBroadcastAtoms(AtomStream &atom,int numc,BroadcastState &bcs)
761761 ((hit.numHops == 1 && (hit.rhost[0].ip == sv->getHost().ip
762762 && hit.uphost.ip == servMgr->serverHost.ip && hit.uphost.port == servMgr->serverHost.port)
763763 || (hit.rhost[1].localIP() && hit.rhost[1].ip == sv->getHost().ip))
764- || chanMgr->findParentHit(hit)))
764+ || (hit.numHops != 1 && chanMgr->findParentHit(hit))))
765765 {
766766 int oldPos = pmem.pos;
767767 hit.writeAtoms(patom, hit.chanID);
--- a/PeerCast.root/PeerCast/core/common/servent.cpp
+++ b/PeerCast.root/PeerCast/core/common/servent.cpp
@@ -878,20 +878,24 @@ bool Servent::handshakeStream(ChanInfo &chanInfo)
878878 }
879879
880880 chanID = chanInfo.id;
881- serventHit.rhost[0].ip = getHost().ip;
882- serventHit.rhost[0].port = listenPort;
883- serventHit.host = serventHit.rhost[0];
881+ serventHit.host.ip = getHost().ip;
882+ serventHit.host.port = listenPort;
883+ if (serventHit.host.globalIP())
884+ serventHit.rhost[0] = serventHit.host;
885+ else
886+ serventHit.rhost[1] = serventHit.host;
884887 serventHit.chanID = chanID;
885888
886889 canStreamLock.on();
887890 chanReady = canStream(ch);
888- if (/*0 && */!chanReady)
891+ if (0 && !chanReady && ch->isPlaying())
889892 {
890- if (servMgr->numStreams(chanID, Servent::T_RELAY, false) == 0)
893+ if (ch->info.getUptime() > 60
894+ && servMgr->numStreams(chanID, Servent::T_RELAY, false) == 0)
891895 {
892896 sourceHit = &ch->sourceHost; // send source host info
893897
894- if (listenPort && ch->info.getUptime() > 60) // if stable
898+ if (listenPort)
895899 {
896900 // connect "this" host later
897901 chanMgr->addHit(serventHit);
@@ -1054,11 +1058,18 @@ bool Servent::handshakeStream(ChanInfo &chanInfo)
10541058
10551059 int error = PCP_ERROR_QUIT+PCP_ERROR_UNAVAILABLE;
10561060
1061+ if (sourceHit) {
1062+ sourceHit->writeAtoms(atom2,chanInfo.id);
1063+ char tmp[50];
1064+ sourceHit->host.toStr(tmp);
1065+ LOG_DEBUG("relay info(sourceHit): %s", tmp);
1066+ }
1067+
10571068 chanMgr->hitlistlock.on();
10581069
10591070 chl = chanMgr->findHitList(chanInfo);
10601071
1061- if (chl)
1072+ if (chl && !sourceHit)
10621073 {
10631074 ChanHit best;
10641075
@@ -1117,25 +1128,18 @@ bool Servent::handshakeStream(ChanInfo &chanInfo)
11171128 cnt++;
11181129 }
11191130
1120- if (sourceHit) {
1121- char tmp[50];
1122- sourceHit->writeAtoms(atom2, chanInfo.id);
1123- sourceHit->host.toStr(tmp);
1124- LOG_DEBUG("relay info(sourceHit): %s", tmp);
1125- best.host.ip = sourceHit->host.ip;
1126- }
1127-
11281131 if (!best.host.ip){
11291132 char tmp[50];
11301133 // chanMgr->hitlistlock.on();
1131- int cnt = chs.getRelayHost(servMgr->serverHost, rhost, remoteID, chl);
1134+ int rhcnt = chs.getRelayHost(servMgr->serverHost, rhost, remoteID, chl);
11321135 // chanMgr->hitlistlock.off();
1133- for (int i = 0; i < cnt; i++){
1136+ for (int i = 0; i < rhcnt; i++){
11341137 chs.best[i].writeAtoms(atom2, chanInfo.id);
11351138 chs.best[i].host.toStr(tmp);
11361139 LOG_DEBUG("relay info: %s hops = %d", tmp, chs.best[i].numHops);
11371140 best.host.ip = chs.best[i].host.ip;
11381141 }
1142+ cnt += rhcnt;
11391143 }
11401144
11411145 if (cnt)
@@ -1352,6 +1356,13 @@ bool Servent::handshakeStream(ChanInfo &chanInfo)
13521356 {
13531357 handshakeIncomingPCP(atom,rhost,remoteID,agent);
13541358 atom.writeInt(PCP_OK,0);
1359+ if (rhost.globalIP())
1360+ serventHit.rhost[0] = rhost;
1361+ else
1362+ serventHit.rhost[1] = rhost;
1363+ serventHit.sessionID = remoteID;
1364+ serventHit.numHops = 1;
1365+ chanMgr->addHit(serventHit);
13551366 }
13561367
13571368 }
--- a/PeerCast.root/PeerCast/core/common/servmgr.cpp
+++ b/PeerCast.root/PeerCast/core/common/servmgr.cpp
@@ -2762,7 +2762,7 @@ int ServMgr::kickUnrelayableHost(GnuID &chid, ChanHit &sendhit)
27622762 Host h = s->getHost();
27632763
27642764 ChanHit hit = s->serventHit;
2765- if (!hit.relay && hit.numRelays == 0)
2765+ if (!hit.relay && hit.numRelays == 0 || hit.firewalled)
27662766 {
27672767 char hostName[256];
27682768 h.toStr(hostName);
--- a/PeerCast.root/PeerCast/core/common/version2.h
+++ b/PeerCast.root/PeerCast/core/common/version2.h
@@ -45,8 +45,8 @@ extern int version_ex; // PP
4545 //#define VERSION_EX 1
4646 static const char *PCP_CLIENT_VERSION_EX_PREFIX = "IM"; // 2bytes only
4747 static const int PCP_CLIENT_VERSION_EX_NUMBER = 27;
48-static const char *PCX_AGENTEX = "PeerCast/0.1218(IM0027-2)";
49-static const char *PCX_VERSTRING_EX = "v0.1218(IM0027-2)";
48+static const char *PCX_AGENTEX = "PeerCast/0.1218(IM0027-3)";
49+static const char *PCX_VERSTRING_EX = "v0.1218(IM0027-3)";
5050 #endif
5151
5252 // ------------------------------------------------
--- a/c:/Git/PeerCast.root/PeerCast/core/common/channel.cpp
+++ b/c:/Git/PeerCast.root/PeerCast/core/common/channel.cpp
@@ -608,6 +608,10 @@ void PeercastSource::stream(Channel *ch)
608608 bool next_yp = false;
609609 bool tracker_check = (ch->trackerHit.host.ip != 0);
610610 int connFailCnt = 0;
611+ int keepDownstreamTime = 7;
612+
613+ if (isIndexTxt(&ch->info))
614+ keepDownstreamTime = 30;
611615
612616 ch->lastStopTime = 0;
613617 ch->bumped = false;
@@ -720,7 +724,9 @@ void PeercastSource::stream(Channel *ch)
720724
721725 chanMgr->hitlistlock.off();
722726
723- if (servMgr->keepDownstreams && ch->lastStopTime && ch->lastStopTime < sys->getTime() - 7) {
727+ if (servMgr->keepDownstreams && ch->lastStopTime
728+ && ch->lastStopTime < sys->getTime() - keepDownstreamTime)
729+ {
724730 ch->lastStopTime = 0;
725731 LOG_DEBUG("------------ disconnect all downstreams");
726732 ChanPacket pack;
@@ -902,7 +908,7 @@ yp0:
902908 ch->trackerHit.lastContact = ctime - 30 + (rand() % 30);
903909
904910 // broadcast source host
905- if (!error && ch->sourceHost.host.ip) { // if closed normally
911+ if (!got503 && !error && ch->sourceHost.host.ip) { // if closed normally
906912 ChanPacket pack;
907913 MemoryStream mem(pack.data,sizeof(pack.data));
908914 AtomStream atom(mem);
@@ -916,7 +922,7 @@ yp0:
916922 }
917923
918924 // broadcast quit to any connected downstream servents
919- if (!servMgr->keepDownstreams || (ch->sourceHost.tracker && !got503) || !error) {
925+ if (!servMgr->keepDownstreams || !got503 && (ch->sourceHost.tracker || !error)) {
920926 ChanPacket pack;
921927 MemoryStream mem(pack.data,sizeof(pack.data));
922928 AtomStream atom(mem);
@@ -1385,6 +1391,17 @@ bool ChannelStream::getStatus(Channel *ch,ChanPacket &pack)
13851391 {
13861392 unsigned int ctime = sys->getTime();
13871393
1394+ if ((ch->isPlaying() == isPlaying)){
1395+ if ((ctime-lastUpdate) < 10){
1396+ return false;
1397+ }
1398+
1399+ if ((ctime-lastCheckTime) < 5){
1400+ return false;
1401+ }
1402+ lastCheckTime = ctime;
1403+ }
1404+
13881405 ChanHitList *chl = chanMgr->findHitListByID(ch->info.id);
13891406
13901407 if (!chl)
@@ -1419,17 +1436,6 @@ bool ChannelStream::getStatus(Channel *ch,ChanPacket &pack)
14191436 int newLocalListeners = ch->localListeners();
14201437 int newLocalRelays = ch->localRelays();
14211438
1422- if ((ch->isPlaying() == isPlaying)){
1423- if ((ctime-lastUpdate) < 10){
1424- return false;
1425- }
1426-
1427- if ((ctime-lastCheckTime) < 10){
1428- return false;
1429- }
1430- lastCheckTime = ctime;
1431- }
1432-
14331439 unsigned int oldp = ch->rawData.getOldestPos();
14341440 unsigned int newp = ch->rawData.getLatestPos();
14351441
@@ -1611,9 +1617,11 @@ int Channel::readStream(Stream &in,ChannelStream *source)
16111617 setStatus(Channel::S_RECEIVING);
16121618 bumped = false;
16131619 }
1614- source->updateStatus(this);
1620+ //source->updateStatus(this);
16151621 }
16161622 }
1623+ if (rawData.lastWriteTime > 0 || rawData.lastSkipTime > 0)
1624+ source->updateStatus(this);
16171625
16181626 unsigned int t = sys->getTime();
16191627 if (t != ptime) {
@@ -1886,9 +1894,11 @@ bool ChanPacketBuffer::findPacket(unsigned int spos, ChanPacket &pack)
18861894 lock.on();
18871895
18881896 unsigned int bound = packets[0].len * ChanPacketBuffer::MAX_PACKETS * 2; // max packets to wait
1889- unsigned int fpos = getStreamPos(firstPos);
1890- unsigned int lpos = getStreamPos(lastPos);
1891- if (spos < fpos && (fpos < lpos || spos > lpos + bound))
1897+ unsigned int fpos = getFirstDataPos();
1898+ unsigned int lpos = getLatestPos();
1899+ if ((spos < fpos && fpos <= lpos && spos != getStreamPosEnd(lastPos)) // --s-----f---l--
1900+ || (spos < fpos && lpos < fpos && spos > lpos + bound) // -l-------s--f--
1901+ || (spos > lpos && lpos >= fpos && spos - lpos > bound)) // --f---l------s-
18921902 spos = fpos;
18931903
18941904
@@ -1917,6 +1927,18 @@ unsigned int ChanPacketBuffer::getLatestPos()
19171927
19181928 }
19191929 // -----------------------------------
1930+unsigned int ChanPacketBuffer::getFirstDataPos()
1931+{
1932+ if (!writePos)
1933+ return 0;
1934+ for(unsigned int i=firstPos; i<=lastPos; i++)
1935+ {
1936+ if (packets[i%MAX_PACKETS].type == ChanPacket::T_DATA)
1937+ return packets[i%MAX_PACKETS].pos;
1938+ }
1939+ return 0;
1940+}
1941+// -----------------------------------
19201942 unsigned int ChanPacketBuffer::getOldestPos()
19211943 {
19221944 if (!writePos)
@@ -3897,6 +3919,15 @@ int ChanHitList::pickSourceHits(ChanHitSearch &chs)
38973919 return 0;
38983920 }
38993921
3922+// -----------------------------------
3923+unsigned int ChanHitList::getSeq()
3924+{
3925+ unsigned int seq;
3926+ seqLock.on();
3927+ seq = riSequence = (riSequence + 1) & 0xffffff;
3928+ seqLock.off();
3929+ return seq;
3930+}
39003931
39013932 // -----------------------------------
39023933 const char *ChanInfo::getTypeStr(TYPE t)
@@ -4703,40 +4734,18 @@ int ChanHitSearch::getRelayHost(Host host1, Host host2, GnuID exID, ChanHitList
47034734 int index = 0;
47044735 int prob;
47054736 int rnd;
4706- static int base = 0x400;
4737+ int base = 0x400;
47074738 ChanHit tmpHit[MAX_RESULTS];
4708- static WLock seqLock;
4709- static unsigned int riSequence = 0;
47104739
47114740 //srand(seed);
47124741 //seed += 11;
47134742
4714- unsigned int seq;
4715- seqLock.on();
4716- seq = riSequence++;
4717- riSequence &= 0xffffff;
4718- seqLock.off();
4719-
4720- Servent *s = servMgr->servents;
4721- while (s) {
4722- if (s->serventHit.rhost[0].port && s->type == Servent::T_RELAY
4723- && s->chanID.isSame(chl->info.id)) {
4724- int i = index % MAX_RESULTS;
4725- if (index < MAX_RESULTS
4726- || tmpHit[i].lastSendSeq > s->serventHit.lastSendSeq) {
4727- s->serventHit.lastSendSeq = seq;
4728- tmpHit[i] = s->serventHit;
4729- tmpHit[i].host = s->serventHit.rhost[0];
4730- index++;
4731- }
4732- }
4733- s = s->next;
4734- }
4743+ unsigned int seq = chl->getSeq();
47354744
47364745 ChanHit *hit = chl->hit;
47374746
47384747 while(hit){
4739- if (hit->host.ip && !hit->dead){
4748+ if (hit->rhost[0].ip && !hit->dead) {
47404749 if (
47414750 (!exID.isSame(hit->sessionID))
47424751 // && (hit->relay)
@@ -4764,7 +4773,6 @@ int ChanHitSearch::getRelayHost(Host host1, Host host2, GnuID exID, ChanHitList
47644773 //rnd = (float)rand() / (float)RAND_MAX;
47654774 rnd = rand() % base;
47664775 if (hit->numHops == 1){
4767-#if 0
47684776 if (tmpHit[index % MAX_RESULTS].numHops == 1){
47694777 if (rnd < prob){
47704778 tmpHit[index % MAX_RESULTS] = *hit;
@@ -4776,9 +4784,8 @@ int ChanHitSearch::getRelayHost(Host host1, Host host2, GnuID exID, ChanHitList
47764784 tmpHit[index % MAX_RESULTS].host = hit->rhost[0];
47774785 index++;
47784786 }
4779-#endif
47804787 } else {
4781- if ((tmpHit[index % MAX_RESULTS].numHops != 1) && (rnd < prob) || rnd == 0){
4788+ if ((tmpHit[index % MAX_RESULTS].numHops != 1) && (rnd < prob)){
47824789 tmpHit[index % MAX_RESULTS] = *hit;
47834790 tmpHit[index % MAX_RESULTS].host = hit->rhost[0];
47844791 index++;
@@ -4822,15 +4829,9 @@ int ChanHitSearch::getRelayHost(Host host1, Host host2, GnuID exID, ChanHitList
48224829 best[use[i]] = tmpHit[i];
48234830 }*/
48244831
4825- int use[MAX_RESULTS];
4826- int i;
4827- for (i = 0; i < cnt; i++) {
4828- use[i] = (i + seq) % cnt;
4829- }
4830-
4831- for (i = 0; i < cnt; i++){
4832+ for (int i = 0; i < cnt; i++){
48324833 // LOG_DEBUG("%d", use[i]);
4833- best[use[i]] = tmpHit[i];
4834+ best[(i + seq) % cnt] = tmpHit[i];
48344835 }
48354836 // for (i = 0; i < cnt; i++){
48364837 // char tmp[50];
--- a/c:/Git/PeerCast.root/PeerCast/core/common/channel.h
+++ b/c:/Git/PeerCast.root/PeerCast/core/common/channel.h
@@ -249,13 +249,16 @@ public:
249249 int getTotalRelays();
250250 int getTotalFirewalled();
251251
252+ unsigned int getSeq();
253+
252254 bool used;
253255 ChanInfo info;
254256 ChanHit *hit;
255257 unsigned int lastHitTime;
256258 ChanHitList *next;
257259
258-
260+ WLock seqLock;
261+ unsigned int riSequence;
259262 };
260263 // ----------------------------------
261264 class ChanHitSearch
--- a/c:/Git/PeerCast.root/PeerCast/core/common/cstream.h
+++ b/c:/Git/PeerCast.root/PeerCast/core/common/cstream.h
@@ -187,6 +187,7 @@ public:
187187
188188 int numPending() {return writePos-readPos;}
189189
190+ unsigned int getFirstDataPos();
190191 unsigned int getLatestPos();
191192 unsigned int getOldestPos();
192193 unsigned int findOldestPos(unsigned int);
--- a/c:/Git/PeerCast.root/PeerCast/core/common/pcp.cpp
+++ b/c:/Git/PeerCast.root/PeerCast/core/common/pcp.cpp
@@ -547,7 +547,7 @@ void PCPStream::readHostAtoms(AtomStream &atom, int numc, BroadcastState &bcs, C
547547 if (sv && sv->getHost().ip == hit.host.ip){
548548 // LOG_DEBUG("set servent's waitPort = %d", hit.host.port);
549549 sv->waitPort = hit.host.port;
550- hit.lastSendSeq = sv->serventHit.lastSendSeq;
550+ //hit.lastSendSeq = sv->serventHit.lastSendSeq;
551551 sv->serventHit = hit;
552552 }
553553 }
@@ -761,7 +761,7 @@ int PCPStream::readBroadcastAtoms(AtomStream &atom,int numc,BroadcastState &bcs)
761761 ((hit.numHops == 1 && (hit.rhost[0].ip == sv->getHost().ip
762762 && hit.uphost.ip == servMgr->serverHost.ip && hit.uphost.port == servMgr->serverHost.port)
763763 || (hit.rhost[1].localIP() && hit.rhost[1].ip == sv->getHost().ip))
764- || chanMgr->findParentHit(hit)))
764+ || (hit.numHops != 1 && chanMgr->findParentHit(hit))))
765765 {
766766 int oldPos = pmem.pos;
767767 hit.writeAtoms(patom, hit.chanID);
--- a/c:/Git/PeerCast.root/PeerCast/core/common/servent.cpp
+++ b/c:/Git/PeerCast.root/PeerCast/core/common/servent.cpp
@@ -878,20 +878,24 @@ bool Servent::handshakeStream(ChanInfo &chanInfo)
878878 }
879879
880880 chanID = chanInfo.id;
881- serventHit.rhost[0].ip = getHost().ip;
882- serventHit.rhost[0].port = listenPort;
883- serventHit.host = serventHit.rhost[0];
881+ serventHit.host.ip = getHost().ip;
882+ serventHit.host.port = listenPort;
883+ if (serventHit.host.globalIP())
884+ serventHit.rhost[0] = serventHit.host;
885+ else
886+ serventHit.rhost[1] = serventHit.host;
884887 serventHit.chanID = chanID;
885888
886889 canStreamLock.on();
887890 chanReady = canStream(ch);
888- if (/*0 && */!chanReady)
891+ if (0 && !chanReady && ch->isPlaying())
889892 {
890- if (servMgr->numStreams(chanID, Servent::T_RELAY, false) == 0)
893+ if (ch->info.getUptime() > 60
894+ && servMgr->numStreams(chanID, Servent::T_RELAY, false) == 0)
891895 {
892896 sourceHit = &ch->sourceHost; // send source host info
893897
894- if (listenPort && ch->info.getUptime() > 60) // if stable
898+ if (listenPort)
895899 {
896900 // connect "this" host later
897901 chanMgr->addHit(serventHit);
@@ -1054,11 +1058,18 @@ bool Servent::handshakeStream(ChanInfo &chanInfo)
10541058
10551059 int error = PCP_ERROR_QUIT+PCP_ERROR_UNAVAILABLE;
10561060
1061+ if (sourceHit) {
1062+ sourceHit->writeAtoms(atom2,chanInfo.id);
1063+ char tmp[50];
1064+ sourceHit->host.toStr(tmp);
1065+ LOG_DEBUG("relay info(sourceHit): %s", tmp);
1066+ }
1067+
10571068 chanMgr->hitlistlock.on();
10581069
10591070 chl = chanMgr->findHitList(chanInfo);
10601071
1061- if (chl)
1072+ if (chl && !sourceHit)
10621073 {
10631074 ChanHit best;
10641075
@@ -1117,25 +1128,18 @@ bool Servent::handshakeStream(ChanInfo &chanInfo)
11171128 cnt++;
11181129 }
11191130
1120- if (sourceHit) {
1121- char tmp[50];
1122- sourceHit->writeAtoms(atom2, chanInfo.id);
1123- sourceHit->host.toStr(tmp);
1124- LOG_DEBUG("relay info(sourceHit): %s", tmp);
1125- best.host.ip = sourceHit->host.ip;
1126- }
1127-
11281131 if (!best.host.ip){
11291132 char tmp[50];
11301133 // chanMgr->hitlistlock.on();
1131- int cnt = chs.getRelayHost(servMgr->serverHost, rhost, remoteID, chl);
1134+ int rhcnt = chs.getRelayHost(servMgr->serverHost, rhost, remoteID, chl);
11321135 // chanMgr->hitlistlock.off();
1133- for (int i = 0; i < cnt; i++){
1136+ for (int i = 0; i < rhcnt; i++){
11341137 chs.best[i].writeAtoms(atom2, chanInfo.id);
11351138 chs.best[i].host.toStr(tmp);
11361139 LOG_DEBUG("relay info: %s hops = %d", tmp, chs.best[i].numHops);
11371140 best.host.ip = chs.best[i].host.ip;
11381141 }
1142+ cnt += rhcnt;
11391143 }
11401144
11411145 if (cnt)
@@ -1352,6 +1356,13 @@ bool Servent::handshakeStream(ChanInfo &chanInfo)
13521356 {
13531357 handshakeIncomingPCP(atom,rhost,remoteID,agent);
13541358 atom.writeInt(PCP_OK,0);
1359+ if (rhost.globalIP())
1360+ serventHit.rhost[0] = rhost;
1361+ else
1362+ serventHit.rhost[1] = rhost;
1363+ serventHit.sessionID = remoteID;
1364+ serventHit.numHops = 1;
1365+ chanMgr->addHit(serventHit);
13551366 }
13561367
13571368 }
--- a/c:/Git/PeerCast.root/PeerCast/core/common/servmgr.cpp
+++ b/c:/Git/PeerCast.root/PeerCast/core/common/servmgr.cpp
@@ -2762,7 +2762,7 @@ int ServMgr::kickUnrelayableHost(GnuID &chid, ChanHit &sendhit)
27622762 Host h = s->getHost();
27632763
27642764 ChanHit hit = s->serventHit;
2765- if (!hit.relay && hit.numRelays == 0)
2765+ if (!hit.relay && hit.numRelays == 0 || hit.firewalled)
27662766 {
27672767 char hostName[256];
27682768 h.toStr(hostName);
--- a/c:/Git/PeerCast.root/PeerCast/core/common/version2.h
+++ b/c:/Git/PeerCast.root/PeerCast/core/common/version2.h
@@ -45,8 +45,8 @@ extern int version_ex; // PP
4545 //#define VERSION_EX 1
4646 static const char *PCP_CLIENT_VERSION_EX_PREFIX = "IM"; // 2bytes only
4747 static const int PCP_CLIENT_VERSION_EX_NUMBER = 27;
48-static const char *PCX_AGENTEX = "PeerCast/0.1218(IM0027-2)";
49-static const char *PCX_VERSTRING_EX = "v0.1218(IM0027-2)";
48+static const char *PCX_AGENTEX = "PeerCast/0.1218(IM0027-3)";
49+static const char *PCX_VERSTRING_EX = "v0.1218(IM0027-3)";
5050 #endif
5151
5252 // ------------------------------------------------