Ticket #16469: walkie_talkie_diff

File walkie_talkie_diff, 8.4 KB (added by gk, 4 years ago)
Line 
1diff --git a/netwerk/protocol/http/nsHttpConnectionMgr.cpp b/netwerk/protocol/http/nsHttpConnectionMgr.cpp
2index a15f584..ce99147 100644
3--- a/netwerk/protocol/http/nsHttpConnectionMgr.cpp
4+++ b/netwerk/protocol/http/nsHttpConnectionMgr.cpp
5@@ -85,6 +85,7 @@ nsHttpConnectionMgr::nsHttpConnectionMgr()
6     , mNumIdleConns(0)
7     , mNumSpdyActiveConns(0)
8     , mNumHalfOpenConns(0)
9+    , mTalkie(0) //walkie
10     , mTimeOfNextWakeUp(UINT64_MAX)
11     , mTimeoutTickArmed(false)
12     , mTimeoutTickNext(1)
13@@ -375,6 +376,10 @@ nsHttpConnectionMgr::SpeculativeConnect(nsHttpConnectionInfo *ci,
14                                         nsIInterfaceRequestor *callbacks,
15                                         uint32_t caps)
16 {
17+
18+    //walkie: do nothing instead.
19+    return NS_OK;
20+
21     MOZ_ASSERT(NS_IsMainThread(), "nsHttpConnectionMgr::SpeculativeConnect called off main thread!");
22 
23     LOG(("nsHttpConnectionMgr::SpeculativeConnect [ci=%s]\n",
24@@ -475,6 +480,7 @@ nsHttpConnectionMgr::UpdateParam(nsParamName name, uint16_t value)
25 nsresult
26 nsHttpConnectionMgr::ProcessPendingQ(nsHttpConnectionInfo *ci)
27 {
28+
29     LOG(("nsHttpConnectionMgr::ProcessPendingQ [ci=%s]\n", ci->HashKey().get()));
30 
31     NS_ADDREF(ci);
32@@ -487,6 +493,7 @@ nsHttpConnectionMgr::ProcessPendingQ(nsHttpConnectionInfo *ci)
33 nsresult
34 nsHttpConnectionMgr::ProcessPendingQ()
35 {
36+
37     LOG(("nsHttpConnectionMgr::ProcessPendingQ [All CI]\n"));
38     return PostEvent(&nsHttpConnectionMgr::OnMsgProcessPendingQ, 0, nullptr);
39 }
40@@ -1082,7 +1089,11 @@ nsHttpConnectionMgr::ProcessPendingQForEntry(nsConnectionEntry *ent, bool consid
41             }
42         }
43 
44+        //walkie
45+        alreadyHalfOpen = false;
46+
47         rv = TryDispatchTransaction(ent, alreadyHalfOpen, trans);
48+
49         if (NS_SUCCEEDED(rv) || (rv != NS_ERROR_NOT_AVAILABLE)) {
50             if (NS_SUCCEEDED(rv))
51                 LOG(("  dispatching pending transaction...\n"));
52@@ -1699,6 +1710,7 @@ nsHttpConnectionMgr::TryDispatchTransaction(nsConnectionEntry *ent,
53     // explicitly marked as unblocked.
54     if (!(caps & NS_HTTP_LOAD_AS_BLOCKING)) {
55         if (!(caps & NS_HTTP_LOAD_UNBLOCKED)) {
56+
57             nsILoadGroupConnectionInfo *loadGroupCI = trans->LoadGroupConnectionInfo();
58             if (loadGroupCI) {
59                 uint32_t blockers = 0;
60@@ -1790,7 +1802,9 @@ nsHttpConnectionMgr::TryDispatchTransaction(nsConnectionEntry *ent,
61     }
62 
63     // step 4: Maybe make a connection?
64-    if (!onlyReusedConnection && allowNewPipelines) {
65+//    if (!onlyReusedConnection && allowNewPipelines) { //walkie: this line is replaced with the original firefox one
66+
67+    if (!onlyReusedConnection) {    //walkie
68         nsresult rv = MakeNewConnection(ent, trans);
69         if (NS_SUCCEEDED(rv)) {
70             // this function returns NOT_AVAILABLE for asynchronous connects
71@@ -1819,7 +1833,6 @@ nsHttpConnectionMgr::TryDispatchTransaction(nsConnectionEntry *ent,
72             ent->mConnInfo->Host(),
73             head ? head->RequestURI().BeginReading() : "<unknown?>");
74 #endif
75
76 
77     return NS_ERROR_NOT_AVAILABLE;                /* queue it */
78 }
79@@ -1833,6 +1846,10 @@ nsHttpConnectionMgr::DispatchTransaction(nsConnectionEntry *ent,
80     int32_t priority = trans->Priority();
81     nsresult rv;
82 
83+    if (mTalkie == 0) { //if we were waiting to talk
84+        mTalkie = 1; //we sure are active now
85+    }
86+
87     LOG(("nsHttpConnectionMgr::DispatchTransaction "
88          "[ci=%s trans=%x caps=%x conn=%x priority=%d]\n",
89          ent->mConnInfo->HashKey().get(), trans, caps, conn, priority));
90@@ -1858,7 +1875,7 @@ nsHttpConnectionMgr::DispatchTransaction(nsConnectionEntry *ent,
91     }
92 
93     MOZ_ASSERT(conn && !conn->Transaction(),
94-               "DispatchTranaction() on non spdy active connection");
95+               "DispatchTransaction() on non spdy active connection");
96 
97     if (!(caps & NS_HTTP_ALLOW_PIPELINING))
98         conn->Classify(nsAHttpTransaction::CLASS_SOLO);
99@@ -2033,6 +2050,14 @@ nsHttpConnectionMgr::ProcessNewTransaction(nsHttpTransaction *trans)
100 
101     ReportProxyTelemetry(ent);
102 
103+    //walkie: new transaction always queued if we can't talk
104+
105+    if (mTalkie == 1) {
106+        InsertTransactionSorted(ent->mPendingQ, trans);
107+        NS_ADDREF(trans);
108+        return NS_OK;
109+    }
110+
111     // Check if the transaction already has a sticky reference to a connection.
112     // If so, then we can just use it directly by transferring its reference
113     // to the new connection variable instead of searching for a new one
114@@ -2081,6 +2106,9 @@ nsHttpConnectionMgr::DecrementActiveConnCount(nsHttpConnection *conn)
115     mNumActiveConns--;
116     if (conn->EverUsedSpdy())
117         mNumSpdyActiveConns--;
118+
119+    //walkie
120+    StartTalkie();
121 }
122 
123 void
124@@ -2095,6 +2123,24 @@ nsHttpConnectionMgr::RecvdConnect()
125 {
126     mNumActiveConns--;
127     ConditionallyStopTimeoutTick();
128+
129+    //walkie
130+    StartTalkie();
131+}
132+
133+void
134+nsHttpConnectionMgr::StartTalkie() //walkie
135+{
136+    if (mNumActiveConns == 0) { //later: mNumActiveConns <= mNumChatteringConns
137+       
138+        FILE * my_log;
139+        my_log = fopen("tor.output", "a");
140+        fprintf(my_log, " --- Starting Talkie --- \n");
141+        fclose(my_log);
142+
143+        mTalkie = 0; //try to stop talking, will be stopped by DispatchTransaction
144+        ProcessPendingQ();
145+    }
146 }
147 
148 nsresult
149@@ -2348,6 +2394,7 @@ nsHttpConnectionMgr::OnMsgCancelTransaction(int32_t reason, void *param)
150 void
151 nsHttpConnectionMgr::OnMsgProcessPendingQ(int32_t, void *param)
152 {
153+
154     MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
155     nsHttpConnectionInfo *ci = (nsHttpConnectionInfo *) param;
156 
157@@ -2486,7 +2533,10 @@ nsHttpConnectionMgr::OnMsgReclaimConnection(int32_t, void *param)
158         }
159     }
160 
161-    OnMsgProcessPendingQ(0, ci); // releases |ci|
162+    //walkie: commented out. never do this.
163+
164+    //OnMsgProcessPendingQ(0, ci); // releases |ci|
165+    NS_RELEASE(ci);
166     NS_RELEASE(conn);
167 }
168 
169@@ -2945,6 +2995,7 @@ nsHalfOpenSocket::SetupStreams(nsISocketTransport **transport,
170     CallQueryInterface(sout, outstream);
171 
172     rv = (*outstream)->AsyncWait(this, 0, 0, nullptr);
173+
174     if (NS_SUCCEEDED(rv))
175         gHttpHandler->ConnMgr()->StartedConnect();
176 
177@@ -3706,11 +3757,15 @@ nsConnectionEntry::RemoveHalfOpen(nsHalfOpenSocket *halfOpen)
178     mHalfOpens.RemoveElement(halfOpen);
179     gHttpHandler->ConnMgr()->mNumHalfOpenConns--;
180 
181-    if (!UnconnectedHalfOpens())
182+    //walkie: commented out.
183+
184+    //if (!UnconnectedHalfOpens())
185         // perhaps this reverted RestrictConnections()
186         // use the PostEvent version of processpendingq to avoid
187         // altering the pending q vector from an arbitrary stack
188-        gHttpHandler->ConnMgr()->ProcessPendingQ(mConnInfo);
189+
190+        //walkie: no.
191+        //gHttpHandler->ConnMgr()->ProcessPendingQ(mConnInfo);
192 }
193 
194 void
195diff --git a/netwerk/protocol/http/nsHttpConnectionMgr.h b/netwerk/protocol/http/nsHttpConnectionMgr.h
196index 0f8f510..fcac54e 100644
197--- a/netwerk/protocol/http/nsHttpConnectionMgr.h
198+++ b/netwerk/protocol/http/nsHttpConnectionMgr.h
199@@ -532,6 +532,7 @@ private:
200     void     DecrementActiveConnCount(nsHttpConnection *);
201     void     StartedConnect();
202     void     RecvdConnect();
203+    void     StartTalkie(); //walkie
204 
205     nsConnectionEntry *GetOrCreateConnectionEntry(nsHttpConnectionInfo *);
206 
207@@ -632,6 +633,8 @@ private:
208     // that are accessed from mCT connection table
209     uint32_t mNumHalfOpenConns;
210 
211+    uint32_t mTalkie; //0: waiting, 1: talking
212+
213     // Holds time in seconds for next wake-up to prune dead connections.
214     uint64_t mTimeOfNextWakeUp;
215     // Timer for next pruning of dead connections.
216diff --git a/netwerk/protocol/http/nsHttpTransaction.cpp b/netwerk/protocol/http/nsHttpTransaction.cpp
217index adc9cbf..9f24d3d 100644
218--- a/netwerk/protocol/http/nsHttpTransaction.cpp
219+++ b/netwerk/protocol/http/nsHttpTransaction.cpp
220@@ -1707,6 +1707,7 @@ nsHttpTransaction::DispatchedAsBlocking()
221 void
222 nsHttpTransaction::RemoveDispatchedAsBlocking()
223 {
224+
225     if (!mLoadGroupCI || !mDispatchedAsBlocking)
226         return;
227 
228@@ -1718,9 +1719,11 @@ nsHttpTransaction::RemoveDispatchedAsBlocking()
229          mLoadGroupCI.get(), blockers));
230 
231     if (NS_SUCCEEDED(rv) && !blockers) {
232+
233         LOG(("nsHttpTransaction %p triggering release of blocked channels.\n",
234              this));
235-        gHttpHandler->ConnMgr()->ProcessPendingQ();
236+        //walkie: don't do this.
237+        //gHttpHandler->ConnMgr()->ProcessPendingQ();
238     }
239 
240     mDispatchedAsBlocking = false;