<div>Hi gurus:</div><div>For below code in client_side.cc, I want to know what's the pinning.serverConnection mean? and what it is used for?</div><div><br></div><div>I want to rewrite the on_unsupported_protocol to support tcp connection (non-http protocol, called httpdns not readable, no http header) and relay it the server.</div><div>Except here, I need assign the server's address and port, where shold I moidify ? the receive part logic ?</div><div>could anyone give me some advisement, thanks.</div><div><style type="text/css">
p, li { white-space: pre-wrap; }
</style>
<pre style="margin-top: 0px; margin-bottom: 0px;"><!--StartFragment--><span style=" font-weight:600; color:#000080;">bool</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;">ConnStateData::initiateTunneledRequest(HttpRequest::Pointer<span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#000080;">const</span><span style=" color:#c0c0c0;"> </span>&cause,<span style=" color:#c0c0c0;"> </span>Http::MethodType<span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#000080;">const</span><span style=" color:#c0c0c0;"> </span>method,<span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#000080;">const</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#000080;">char</span><span style=" color:#c0c0c0;"> </span>*reason,<span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#000080;">const</span><span style=" color:#c0c0c0;"> </span>SBuf<span style=" color:#c0c0c0;"> </span>&payload)</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;">{</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span><span style=" font-style:italic; color:#808080;">//</span><span style=" color:#c0c0c0;"> </span><span style=" font-style:italic; color:#808080;">fake</span><span style=" color:#c0c0c0;"> </span><span style=" font-style:italic; color:#808080;">a</span><span style=" color:#c0c0c0;"> </span><span style=" font-style:italic; color:#808080;">CONNECT</span><span style=" color:#c0c0c0;"> </span><span style=" font-style:italic; color:#808080;">request</span><span style=" color:#c0c0c0;"> </span><span style=" font-style:italic; color:#808080;">to</span><span style=" color:#c0c0c0;"> </span><span style=" font-style:italic; color:#808080;">force</span><span style=" color:#c0c0c0;"> </span><span style=" font-style:italic; color:#808080;">connState</span><span style=" color:#c0c0c0;"> </span><span style=" font-style:italic; color:#808080;">to</span><span style=" color:#c0c0c0;"> </span><span style=" font-style:italic; color:#808080;">tunnel</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span>SBuf<span style=" color:#c0c0c0;"> </span>connectHost;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span><span style=" font-weight:600; color:#000080;">unsigned</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#000080;">short</span><span style=" color:#c0c0c0;"> </span>connectPort<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" color:#0000ff;">0</span>;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span><span style=" font-weight:600; color:#000080;">if</span><span style=" color:#c0c0c0;"> </span>(<span style=" font-weight:600; color:#660e7a;">pinning</span>.<span style=" font-weight:600; color:#660e7a;">serverConnection</span><span style=" color:#c0c0c0;"> </span>!=<span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#000080;">nullptr</span>)<span style=" color:#c0c0c0;"> </span>{</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">        </span><span style=" font-weight:600; color:#000080;">static</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#000080;">char</span><span style=" color:#c0c0c0;"> </span>ip[<span style=" font-weight:600; color:#000080;">MAX_IPSTRLEN</span>];</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">        </span>connectHost.assign(<span style=" font-weight:600; color:#660e7a;">pinning</span>.<span style=" font-weight:600; color:#660e7a;">serverConnection</span>-><span style=" font-weight:600; color:#660e7a;">remote</span>.toStr(ip,<span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#000080;">sizeof</span>(ip)));</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">        </span>connectPort<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#660e7a;">pinning</span>.<span style=" font-weight:600; color:#660e7a;">serverConnection</span>-><span style=" font-weight:600; color:#660e7a;">remote</span>.port();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span>}<span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#000080;">else</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#000080;">if</span><span style=" color:#c0c0c0;"> </span>(cause<span style=" color:#c0c0c0;"> </span>&&<span style=" color:#c0c0c0;"> </span>cause-><span style=" font-weight:600; color:#660e7a;">method</span><span style=" color:#c0c0c0;"> </span>==<span style=" color:#c0c0c0;"> </span>Http::METHOD_CONNECT)<span style=" color:#c0c0c0;"> </span>{</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">        </span><span style=" font-style:italic; color:#808080;">//</span><span style=" color:#c0c0c0;"> </span><span style=" font-style:italic; color:#808080;">We</span><span style=" color:#c0c0c0;"> </span><span style=" font-style:italic; color:#808080;">are</span><span style=" color:#c0c0c0;"> </span><span style=" font-style:italic; color:#808080;">inside</span><span style=" color:#c0c0c0;"> </span><span style=" font-style:italic; color:#808080;">a</span><span style=" color:#c0c0c0;"> </span><span style=" font-style:italic; color:#808080;">(not</span><span style=" color:#c0c0c0;"> </span><span style=" font-style:italic; color:#808080;">fully</span><span style=" color:#c0c0c0;"> </span><span style=" font-style:italic; color:#808080;">established)</span><span style=" color:#c0c0c0;"> </span><span style=" font-style:italic; color:#808080;">CONNECT</span><span style=" color:#c0c0c0;"> </span><span style=" font-style:italic; color:#808080;">request</span></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">        </span>connectHost<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span>cause-><span style=" font-weight:600; color:#660e7a;">url</span>.host();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">        </span>connectPort<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span>cause-><span style=" font-weight:600; color:#660e7a;">url</span>.port();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span>}<span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#000080;">else</span><span style=" color:#c0c0c0;"> </span>{</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">        </span>debugs(<span style=" color:#0000ff;">33</span>,<span style=" color:#c0c0c0;"> </span><span style=" color:#0000ff;">2</span>,<span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#008000;">"Not</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#008000;">able</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#008000;">to</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#008000;">compute</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#008000;">URL,</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#008000;">abort</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#008000;">request</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#008000;">tunneling</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#008000;">for</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#008000;">"</span><span style=" color:#c0c0c0;"> </span><<<span style=" color:#c0c0c0;"> </span>reason);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">        </span><span style=" font-weight:600; color:#000080;">return</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#000080;">false</span>;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span>}</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><br></pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span>debugs(<span style=" color:#0000ff;">33</span>,<span style=" color:#c0c0c0;"> </span><span style=" color:#0000ff;">2</span>,<span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#008000;">"Request</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#008000;">tunneling</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#008000;">for</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#008000;">"</span><span style=" color:#c0c0c0;"> </span><<<span style=" color:#c0c0c0;"> </span>reason);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span>ClientHttpRequest<span style=" color:#c0c0c0;"> </span>*http<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span>buildFakeRequest(method,<span style=" color:#c0c0c0;"> </span>connectHost,<span style=" color:#c0c0c0;"> </span>connectPort,<span style=" color:#c0c0c0;"> </span>payload);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span>HttpRequest::Pointer<span style=" color:#c0c0c0;"> </span>request<span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span>http-><span style=" font-weight:600; color:#660e7a;">request</span>;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span>request-><span style=" font-weight:600; color:#660e7a;">flags</span>.<span style=" font-weight:600; color:#660e7a;">forceTunnel</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#000080;">true</span>;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span>http-><span style=" font-weight:600; color:#660e7a;">calloutContext</span><span style=" color:#c0c0c0;"> </span>=<span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#000080;">new</span><span style=" color:#c0c0c0;"> </span>ClientRequestContext(http);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span>http->doCallouts();</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span>clientProcessRequestFinished(<span style=" font-weight:600; color:#000080;">this</span>,<span style=" color:#c0c0c0;"> </span>request);</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;"><span style=" color:#c0c0c0;">    </span><span style=" font-weight:600; color:#000080;">return</span><span style=" color:#c0c0c0;"> </span><span style=" font-weight:600; color:#000080;">true</span>;</pre>
<pre style="margin-top: 0px; margin-bottom: 0px;">}<!--EndFragment--></pre></div><div><br></div>