Unverified Commit 1b5d1f52 authored by Hannah Howard's avatar Hannah Howard Committed by GitHub

Merge pull request #13 from ipfs/feat/graph-sync-network

feat(network): first version of GraphSyncNetwork
parents 13985127 3d45ae0a
<?xml version="1.0" encoding="UTF-8" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentScriptType="application/ecmascript" contentStyleType="text/css" height="1506px" preserveAspectRatio="none" style="width:4605px;height:1506px;" version="1.1" viewBox="0 0 4605 1506" width="4605px" zoomAndPan="magnify"><defs><filter height="300%" id="f1fpjge6j4amxm" width="300%" x="-1" y="-1"><feGaussianBlur result="blurOut" stdDeviation="2.0"/><feColorMatrix in="blurOut" result="blurOut2" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .4 0"/><feOffset dx="4.0" dy="4.0" in="blurOut2" result="blurOut3"/><feBlend in="SourceGraphic" in2="blurOut3" mode="normal"/></filter></defs><g><!--cluster go-ipld-format--><polygon fill="#FFFFFF" filter="url(#f1fpjge6j4amxm)" points="1324,240.5,1443,240.5,1450,262.9883,1453,262.9883,1453,323.5,1324,323.5,1324,240.5" style="stroke: #000000; stroke-width: 1.5;"/><line style="stroke: #000000; stroke-width: 1.5;" x1="1324" x2="1450" y1="262.9883" y2="262.9883"/><text fill="#000000" font-family="sans-serif" font-size="14" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="113" x="1328" y="256.0352">go-ipld-format</text><!--cluster go-selector--><polygon fill="#FFFFFF" filter="url(#f1fpjge6j4amxm)" points="14,400,104,400,111,422.4883,1658,422.4883,1658,509,14,509,14,400" style="stroke: #000000; stroke-width: 1.5;"/><line style="stroke: #000000; stroke-width: 1.5;" x1="14" x2="111" y1="422.4883" y2="422.4883"/><text fill="#000000" font-family="sans-serif" font-size="14" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="84" x="18" y="415.5352">go-selector</text><!--cluster go-graphsync--><polygon fill="#FFFFFF" filter="url(#f1fpjge6j4amxm)" points="1666,195,1772,195,1779,217.4883,4583,217.4883,4583,1494,1666,1494,1666,195" style="stroke: #000000; stroke-width: 1.5;"/><line style="stroke: #000000; stroke-width: 1.5;" x1="1666" x2="1779" y1="217.4883" y2="217.4883"/><text fill="#000000" font-family="sans-serif" font-size="14" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="100" x="1670" y="210.5352">go-graphsync</text><!--cluster network--><polygon fill="#FFFFFF" filter="url(#f1fpjge6j4amxm)" points="1674,768,1739,768,1746,790.4883,2948,790.4883,2948,1289,1674,1289,1674,768" style="stroke: #000000; stroke-width: 1.5;"/><line style="stroke: #000000; stroke-width: 1.5;" x1="1674" x2="1746" y1="790.4883" y2="790.4883"/><text fill="#000000" font-family="sans-serif" font-size="14" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="59" x="1678" y="783.5352">network</text><!--cluster requestmanager--><polygon fill="#FFFFFF" filter="url(#f1fpjge6j4amxm)" points="1674,540,1796,540,1803,562.4883,2598,562.4883,2598,675,1674,675,1674,540" style="stroke: #000000; stroke-width: 1.5;"/><line style="stroke: #000000; stroke-width: 1.5;" x1="1674" x2="1803" y1="562.4883" y2="562.4883"/><text fill="#000000" font-family="sans-serif" font-size="14" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="116" x="1678" y="555.5352">requestmanager</text><!--cluster responsemanager--><polygon fill="#FFFFFF" filter="url(#f1fpjge6j4amxm)" points="2616,546.5,2749,546.5,2756,568.9883,3345,568.9883,3345,668.5,2616,668.5,2616,546.5" style="stroke: #000000; stroke-width: 1.5;"/><line style="stroke: #000000; stroke-width: 1.5;" x1="2616" x2="2756" y1="568.9883" y2="568.9883"/><text fill="#000000" font-family="sans-serif" font-size="14" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="127" x="2620" y="562.0352">responsemanager</text><!--cluster message--><polygon fill="#FFFFFF" filter="url(#f1fpjge6j4amxm)" points="2956,970,3025,970,3032,992.4883,4575,992.4883,4575,1486,2956,1486,2956,970" style="stroke: #000000; stroke-width: 1.5;"/><line style="stroke: #000000; stroke-width: 1.5;" x1="2956" x2="3032" y1="992.4883" y2="992.4883"/><text fill="#000000" font-family="sans-serif" font-size="14" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="63" x="2960" y="985.5352">message</text><!--cluster go-filecoin--><polygon fill="#FFFFFF" filter="url(#f1fpjge6j4amxm)" points="1175,16,1262,16,1269,38.4883,1541,38.4883,1541,164,1175,164,1175,16" style="stroke: #000000; stroke-width: 1.5;"/><line style="stroke: #000000; stroke-width: 1.5;" x1="1175" x2="1269" y1="38.4883" y2="38.4883"/><text fill="#000000" font-family="sans-serif" font-size="14" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="81" x="1179" y="31.5352">go-filecoin</text><!--class Node--><rect fill="#FEFECE" filter="url(#f1fpjge6j4amxm)" height="48" id="Node" style="stroke: #A80036; stroke-width: 1.5;" width="63" x="1342.5" y="267.5"/><ellipse cx="1357.5" cy="283.5" fill="#B4A7E5" rx="11" ry="11" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M1353.4277,279.2651 L1353.4277,277.1069 L1360.8071,277.1069 L1360.8071,279.2651 L1358.3418,279.2651 L1358.3418,287.3418 L1360.8071,287.3418 L1360.8071,289.5 L1353.4277,289.5 L1353.4277,287.3418 L1355.8931,287.3418 L1355.8931,279.2651 Z "/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacingAndGlyphs" textLength="31" x="1371.5" y="288.0352">Node</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="1343.5" x2="1404.5" y1="299.5" y2="299.5"/><line style="stroke: #A80036; stroke-width: 1.5;" x1="1343.5" x2="1404.5" y1="307.5" y2="307.5"/><!--class Selector--><rect fill="#FEFECE" filter="url(#f1fpjge6j4amxm)" height="48" id="Selector" style="stroke: #A80036; stroke-width: 1.5;" width="77" x="383.5" y="440"/><ellipse cx="398.5" cy="456" fill="#B4A7E5" rx="11" ry="11" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M394.4277,451.7651 L394.4277,449.6069 L401.8071,449.6069 L401.8071,451.7651 L399.3418,451.7651 L399.3418,459.8418 L401.8071,459.8418 L401.8071,462 L394.4277,462 L394.4277,459.8418 L396.8931,459.8418 L396.8931,451.7651 Z "/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacingAndGlyphs" textLength="45" x="412.5" y="460.5352">Selector</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="384.5" x2="459.5" y1="472" y2="472"/><line style="stroke: #A80036; stroke-width: 1.5;" x1="384.5" x2="459.5" y1="480" y2="480"/><!--class SelectionResponse--><rect fill="#FEFECE" filter="url(#f1fpjge6j4amxm)" height="48" id="SelectionResponse" style="stroke: #A80036; stroke-width: 1.5;" width="138" x="1001" y="440"/><ellipse cx="1016" cy="456" fill="#B4A7E5" rx="11" ry="11" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M1011.9277,451.7651 L1011.9277,449.6069 L1019.3071,449.6069 L1019.3071,451.7651 L1016.8418,451.7651 L1016.8418,459.8418 L1019.3071,459.8418 L1019.3071,462 L1011.9277,462 L1011.9277,459.8418 L1014.3931,459.8418 L1014.3931,451.7651 Z "/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacingAndGlyphs" textLength="106" x="1030" y="460.5352">SelectionResponse</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="1002" x2="1138" y1="472" y2="472"/><line style="stroke: #A80036; stroke-width: 1.5;" x1="1002" x2="1138" y1="480" y2="480"/><!--class SelectionTraverser--><rect fill="#FEFECE" filter="url(#f1fpjge6j4amxm)" height="73.9102" id="SelectionTraverser" style="stroke: #A80036; stroke-width: 1.5;" width="170" x="761" y="427"/><ellipse cx="790.4" cy="443" fill="#B4A7E5" rx="11" ry="11" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M786.3277,438.7651 L786.3277,436.6069 L793.7071,436.6069 L793.7071,438.7651 L791.2418,438.7651 L791.2418,446.8418 L793.7071,446.8418 L793.7071,449 L786.3277,449 L786.3277,446.8418 L788.7931,446.8418 L788.7931,438.7651 Z "/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacingAndGlyphs" textLength="106" x="807.6" y="447.5352">SelectionTraverser</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="762" x2="930" y1="459" y2="459"/><line style="stroke: #A80036; stroke-width: 1.5;" x1="762" x2="930" y1="467" y2="467"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="158" x="767" y="481.6348">Next() SelectionResponse, err</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="44" x="767" y="494.5898">Cancel()</text><!--class GetBlockFunc--><rect fill="#FEFECE" filter="url(#f1fpjge6j4amxm)" height="48" id="GetBlockFunc" style="stroke: #A80036; stroke-width: 1.5;" width="230" x="496" y="440"/><ellipse cx="511" cy="456" fill="#B4A7E5" rx="11" ry="11" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M506.9277,451.7651 L506.9277,449.6069 L514.3071,449.6069 L514.3071,451.7651 L511.8418,451.7651 L511.8418,459.8418 L514.3071,459.8418 L514.3071,462 L506.9277,462 L506.9277,459.8418 L509.3931,459.8418 L509.3931,451.7651 Z "/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacingAndGlyphs" textLength="198" x="525" y="460.5352">GetBlockFunc func(cid) block.Block</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="497" x2="725" y1="472" y2="472"/><line style="stroke: #A80036; stroke-width: 1.5;" x1="497" x2="725" y1="480" y2="480"/><!--class SelectorQuerier--><rect fill="#FEFECE" filter="url(#f1fpjge6j4amxm)" height="73.9102" id="SelectorQuerier" style="stroke: #A80036; stroke-width: 1.5;" width="475" x="1174.5" y="427"/><ellipse cx="1363.75" cy="443" fill="#B4A7E5" rx="11" ry="11" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M1359.6777,438.7651 L1359.6777,436.6069 L1367.0571,436.6069 L1367.0571,438.7651 L1364.5918,438.7651 L1364.5918,446.8418 L1367.0571,446.8418 L1367.0571,449 L1359.6777,449 L1359.6777,446.8418 L1362.1431,446.8418 L1362.1431,438.7651 Z "/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacingAndGlyphs" textLength="88" x="1384.25" y="447.5352">SelectorQuerier</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="1175.5" x2="1648.5" y1="459" y2="459"/><line style="stroke: #A80036; stroke-width: 1.5;" x1="1175.5" x2="1648.5" y1="467" y2="467"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="235" x="1180.5" y="481.6348">Select(Selector, root Cid) SelectionTraverser</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="463" x="1180.5" y="494.5898">Validate(Selector, root Cid, incomingResponses SelectionTraverser) SelectionTraverser</text><rect fill="#FEFECE" filter="url(#f1fpjge6j4amxm)" height="37.9102" style="stroke: #A80036; stroke-width: 1.5;" width="326" x="22" y="445"/><text fill="#000000" font-family="sans-serif" font-size="12" lengthAdjust="spacingAndGlyphs" textLength="143" x="113.5" y="458.6016">Package Public Functions</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="23" x2="347" y1="463.1328" y2="463.1328"/><text fill="#000000" font-family="sans-serif" font-size="10" lengthAdjust="spacingAndGlyphs" textLength="314" x="28" y="476.8008">NewSelectorQuerier(getBlockFunc GetBlockFunc) SelectorQuerier</text><!--class GraphSync--><rect fill="#FEFECE" filter="url(#f1fpjge6j4amxm)" height="138.6855" id="GraphSync" style="stroke: #A80036; stroke-width: 1.5;" width="460" x="1798" y="222"/><ellipse cx="1993.25" cy="238" fill="#ADD1B2" rx="11" ry="11" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M1996.2231,243.6431 Q1995.6421,243.9419 1995.0029,244.0913 Q1994.3638,244.2407 1993.6582,244.2407 Q1991.1514,244.2407 1989.8315,242.5889 Q1988.5117,240.937 1988.5117,237.8159 Q1988.5117,234.6865 1989.8315,233.0347 Q1991.1514,231.3828 1993.6582,231.3828 Q1994.3638,231.3828 1995.0112,231.5322 Q1995.6587,231.6816 1996.2231,231.9805 L1996.2231,234.7031 Q1995.5923,234.1221 1994.9988,233.8523 Q1994.4053,233.5825 1993.7744,233.5825 Q1992.4297,233.5825 1991.7449,234.6492 Q1991.0601,235.7158 1991.0601,237.8159 Q1991.0601,239.9077 1991.7449,240.9744 Q1992.4297,242.041 1993.7744,242.041 Q1994.4053,242.041 1994.9988,241.7712 Q1995.5923,241.5015 1996.2231,240.9204 Z "/><text fill="#000000" font-family="sans-serif" font-size="12" lengthAdjust="spacingAndGlyphs" textLength="61" x="2013.75" y="242.5352">GraphSync</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="1799" x2="2257" y1="254" y2="254"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="160" x="1804" y="268.6348">network : GraphySyncNetwork</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="185" x="1804" y="281.5898">requestManager : RequestManager</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="200" x="1804" y="294.5449">responseManager: ResponseManager</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="174" x="1804" y="307.5">selectorQuerier: SelectorQuerier</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="1799" x2="2257" y1="313.8203" y2="313.8203"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="347" x="1804" y="328.4551">Request(p peer.ID, selector Selector, root Cid) SelectionTraverser</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="448" x="1804" y="341.4102">ReceiveMessage(ctx context.Context, sender peer.ID, incoming GraphSyncMessage)</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="104" x="1804" y="354.3652">ReceiveError(error)</text><rect fill="#FEFECE" filter="url(#f1fpjge6j4amxm)" height="37.9102" style="stroke: #A80036; stroke-width: 1.5;" width="490" x="2293" y="272.5"/><text fill="#000000" font-family="sans-serif" font-size="12" lengthAdjust="spacingAndGlyphs" textLength="135" x="2470.5" y="286.1016">PackagePublicFunctions</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="2294" x2="2782" y1="290.6328" y2="290.6328"/><text fill="#000000" font-family="sans-serif" font-size="10" lengthAdjust="spacingAndGlyphs" textLength="478" x="2299" y="304.3008">New(ctx context.Context, network GraphSyncNetwork, selectorQuerier SelectorQuerier) GraphSync</text><!--class Receiver--><rect fill="#FEFECE" filter="url(#f1fpjge6j4amxm)" height="73.9102" id="Receiver" style="stroke: #A80036; stroke-width: 1.5;" width="460" x="2129" y="795"/><ellipse cx="2330.25" cy="811" fill="#B4A7E5" rx="11" ry="11" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M2326.1777,806.7651 L2326.1777,804.6069 L2333.5571,804.6069 L2333.5571,806.7651 L2331.0918,806.7651 L2331.0918,814.8418 L2333.5571,814.8418 L2333.5571,817 L2326.1777,817 L2326.1777,814.8418 L2328.6431,814.8418 L2328.6431,806.7651 Z "/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacingAndGlyphs" textLength="49" x="2350.75" y="815.5352">Receiver</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="2130" x2="2588" y1="827" y2="827"/><line style="stroke: #A80036; stroke-width: 1.5;" x1="2130" x2="2588" y1="835" y2="835"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="448" x="2135" y="849.6348">ReceiveMessage(ctx context.Context, sender peer.ID, incoming GraphSyncMessage)</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="104" x="2135" y="862.5898">ReceiveError(error)</text><!--class GraphSyncNetwork--><rect fill="#FEFECE" filter="url(#f1fpjge6j4amxm)" height="73.9102" id="GraphSyncNetwork" style="stroke: #A80036; stroke-width: 1.5;" width="411" x="1682.5" y="795"/><ellipse cx="1829.25" cy="811" fill="#B4A7E5" rx="11" ry="11" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M1825.1777,806.7651 L1825.1777,804.6069 L1832.5571,804.6069 L1832.5571,806.7651 L1830.0918,806.7651 L1830.0918,814.8418 L1832.5571,814.8418 L1832.5571,817 L1825.1777,817 L1825.1777,814.8418 L1827.6431,814.8418 L1827.6431,806.7651 Z "/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacingAndGlyphs" textLength="109" x="1849.75" y="815.5352">GraphSyncNetwork</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="1683.5" x2="2092.5" y1="827" y2="827"/><line style="stroke: #A80036; stroke-width: 1.5;" x1="1683.5" x2="2092.5" y1="835" y2="835"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="399" x="1688.5" y="849.6348">SendMessage(ctx context.Context, receiver peer.Id, m GraphSyncMessage)</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="161" x="1688.5" y="862.5898">SetDelegate(receiver Receiver)</text><!--class libP2PGraphSyncNetwork--><rect fill="#FEFECE" filter="url(#f1fpjge6j4amxm)" height="48" id="libP2PGraphSyncNetwork" style="stroke: #A80036; stroke-width: 1.5;" width="177" x="2693.5" y="1233"/><ellipse cx="2708.5" cy="1249" fill="#ADD1B2" rx="11" ry="11" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M2711.4731,1254.6431 Q2710.8921,1254.9419 2710.2529,1255.0913 Q2709.6138,1255.2407 2708.9082,1255.2407 Q2706.4014,1255.2407 2705.0815,1253.5889 Q2703.7617,1251.937 2703.7617,1248.8159 Q2703.7617,1245.6865 2705.0815,1244.0347 Q2706.4014,1242.3828 2708.9082,1242.3828 Q2709.6138,1242.3828 2710.2612,1242.5322 Q2710.9087,1242.6816 2711.4731,1242.9805 L2711.4731,1245.7031 Q2710.8423,1245.1221 2710.2488,1244.8523 Q2709.6553,1244.5825 2709.0244,1244.5825 Q2707.6797,1244.5825 2706.9949,1245.6492 Q2706.3101,1246.7158 2706.3101,1248.8159 Q2706.3101,1250.9077 2706.9949,1251.9744 Q2707.6797,1253.041 2709.0244,1253.041 Q2709.6553,1253.041 2710.2488,1252.7712 Q2710.8423,1252.5015 2711.4731,1251.9204 Z "/><text fill="#000000" font-family="sans-serif" font-size="12" lengthAdjust="spacingAndGlyphs" textLength="145" x="2722.5" y="1253.5352">libP2PGraphSyncNetwork</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="2694.5" x2="2869.5" y1="1265" y2="1265"/><line style="stroke: #A80036; stroke-width: 1.5;" x1="2694.5" x2="2869.5" y1="1273" y2="1273"/><rect fill="#FEFECE" filter="url(#f1fpjge6j4amxm)" height="61.4648" style="stroke: #A80036; stroke-width: 1.5;" width="316" x="2624" y="801.5"/><text fill="#000000" font-family="sans-serif" font-size="12" lengthAdjust="spacingAndGlyphs" textLength="143" x="2710.5" y="815.1016">Package Public Functions</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="2625" x2="2939" y1="819.6328" y2="819.6328"/><text fill="#000000" font-family="sans-serif" font-size="10" lengthAdjust="spacingAndGlyphs" textLength="201" x="2630" y="833.3008">NewLibP2PNetwork(host libp2pHost.Host,</text><text fill="#000000" font-family="sans-serif" font-size="10" lengthAdjust="spacingAndGlyphs" textLength="304" x="2630" y="845.0781">decodeSelectionResponseFunc: DecodeSelectionResponseFunc,</text><text fill="#000000" font-family="sans-serif" font-size="10" lengthAdjust="spacingAndGlyphs" textLength="296" x="2630" y="856.8555">decodeSelectorFunc: DecodeSelectorFunc) GraphSyncNetwork</text><!--class RequestManager--><rect fill="#FEFECE" filter="url(#f1fpjge6j4amxm)" height="99.8203" id="RequestManager" style="stroke: #A80036; stroke-width: 1.5;" width="385" x="2204.5" y="567"/><ellipse cx="2344.25" cy="583" fill="#ADD1B2" rx="11" ry="11" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M2347.2231,588.6431 Q2346.6421,588.9419 2346.0029,589.0913 Q2345.3638,589.2407 2344.6582,589.2407 Q2342.1514,589.2407 2340.8315,587.5889 Q2339.5117,585.937 2339.5117,582.8159 Q2339.5117,579.6865 2340.8315,578.0347 Q2342.1514,576.3828 2344.6582,576.3828 Q2345.3638,576.3828 2346.0112,576.5322 Q2346.6587,576.6816 2347.2231,576.9805 L2347.2231,579.7031 Q2346.5923,579.1221 2345.9988,578.8523 Q2345.4053,578.5825 2344.7744,578.5825 Q2343.4297,578.5825 2342.7449,579.6492 Q2342.0601,580.7158 2342.0601,582.8159 Q2342.0601,584.9077 2342.7449,585.9744 Q2343.4297,587.041 2344.7744,587.041 Q2345.4053,587.041 2345.9988,586.7712 Q2346.5923,586.5015 2347.2231,585.9204 Z "/><text fill="#000000" font-family="sans-serif" font-size="12" lengthAdjust="spacingAndGlyphs" textLength="97" x="2364.75" y="587.5352">RequestManager</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="2205.5" x2="2588.5" y1="599" y2="599"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="154" x="2210.5" y="613.6348">network : GraphSyncNetwork</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="174" x="2210.5" y="626.5898">selectorQuerier: SelectorQuerier</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="2205.5" x2="2588.5" y1="632.9102" y2="632.9102"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="373" x="2210.5" y="647.5449">SendRequest(p peer.ID, selector Selector, root Cid) SelectionTraverser</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="285" x="2210.5" y="660.5">ProcessResponses(responses []GraphSyncResponse)</text><path d="M1682.5,589 L1682.5,644.9316 L2169.5,644.9316 L2169.5,599 L2159.5,589 L1682.5,589 " fill="#FBFB77" filter="url(#f1fpjge6j4amxm)" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M2159.5,589 L2159.5,599 L2169.5,599 L2159.5,589 " fill="#FBFB77" style="stroke: #A80036; stroke-width: 1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="339" x="1688.5" y="606.5684">The ResponseManager uses Validate from go-selector</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="466" x="1688.5" y="621.8789">to filter incoming Responses based on whether they are valid and produce</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="277" x="1688.5" y="637.1895">a traverser that only returns valid responses</text><!--class ResponseManager--><rect fill="#FEFECE" filter="url(#f1fpjge6j4amxm)" height="86.8652" id="ResponseManager" style="stroke: #A80036; stroke-width: 1.5;" width="330" x="3007" y="573.5"/><ellipse cx="3114.75" cy="589.5" fill="#ADD1B2" rx="11" ry="11" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M3117.7231,595.1431 Q3117.1421,595.4419 3116.5029,595.5913 Q3115.8638,595.7407 3115.1582,595.7407 Q3112.6514,595.7407 3111.3315,594.0889 Q3110.0117,592.437 3110.0117,589.3159 Q3110.0117,586.1865 3111.3315,584.5347 Q3112.6514,582.8828 3115.1582,582.8828 Q3115.8638,582.8828 3116.5112,583.0322 Q3117.1587,583.1816 3117.7231,583.4805 L3117.7231,586.2031 Q3117.0923,585.6221 3116.4988,585.3523 Q3115.9053,585.0825 3115.2744,585.0825 Q3113.9297,585.0825 3113.2449,586.1492 Q3112.5601,587.2158 3112.5601,589.3159 Q3112.5601,591.4077 3113.2449,592.4744 Q3113.9297,593.541 3115.2744,593.541 Q3115.9053,593.541 3116.4988,593.2712 Q3117.0923,593.0015 3117.7231,592.4204 Z "/><text fill="#000000" font-family="sans-serif" font-size="12" lengthAdjust="spacingAndGlyphs" textLength="106" x="3135.25" y="594.0352">ResponseManager</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="3008" x2="3336" y1="605.5" y2="605.5"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="160" x="3013" y="620.1348">network : GraphySyncNetwork</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="174" x="3013" y="633.0898">selectorQuerier: SelectorQuerier</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="3008" x2="3336" y1="639.4102" y2="639.4102"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="318" x="3013" y="654.0449">ProcessRequests(p peer.ID, requests []GraphSyncRequests)</text><path d="M2624.5,573.5 L2624.5,660.0527 L2971.5,660.0527 L2971.5,583.5 L2961.5,573.5 L2624.5,573.5 " fill="#FBFB77" filter="url(#f1fpjge6j4amxm)" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M2961.5,573.5 L2961.5,583.5 L2971.5,583.5 L2961.5,573.5 " fill="#FBFB77" style="stroke: #A80036; stroke-width: 1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="326" x="2630.5" y="591.0684">The ResponseManager uses Select from go-selector</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="313" x="2630.5" y="606.3789">to translate the raw bytes into a selector and then</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="284" x="2630.5" y="621.6895">traverse the graph to produce a list of blocks</text><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="0" x="2634.5" y="637"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="284" x="2630.5" y="652.3105">Question: how to know if response is partial?</text><!--class DecodeSelectionResponseFunc--><rect fill="#FEFECE" filter="url(#f1fpjge6j4amxm)" height="48" id="DecodeSelectionResponseFunc" style="stroke: #A80036; stroke-width: 1.5;" width="387" x="4179.5" y="1029.5"/><ellipse cx="4194.5" cy="1045.5" fill="#B4A7E5" rx="11" ry="11" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M4190.4277,1041.2651 L4190.4277,1039.1069 L4197.8071,1039.1069 L4197.8071,1041.2651 L4195.3418,1041.2651 L4195.3418,1049.3418 L4197.8071,1049.3418 L4197.8071,1051.5 L4190.4277,1051.5 L4190.4277,1049.3418 L4192.8931,1049.3418 L4192.8931,1041.2651 Z "/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacingAndGlyphs" textLength="355" x="4208.5" y="1050.0352">DecodeSelectionResponseFunc func([]byte) SelectionResponse</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="4180.5" x2="4565.5" y1="1061.5" y2="1061.5"/><line style="stroke: #A80036; stroke-width: 1.5;" x1="4180.5" x2="4565.5" y1="1069.5" y2="1069.5"/><!--class DecodeSelectorFunc--><rect fill="#FEFECE" filter="url(#f1fpjge6j4amxm)" height="48" id="DecodeSelectorFunc" style="stroke: #A80036; stroke-width: 1.5;" width="265" x="3879.5" y="1029.5"/><ellipse cx="3894.5" cy="1045.5" fill="#B4A7E5" rx="11" ry="11" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M3890.4277,1041.2651 L3890.4277,1039.1069 L3897.8071,1039.1069 L3897.8071,1041.2651 L3895.3418,1041.2651 L3895.3418,1049.3418 L3897.8071,1049.3418 L3897.8071,1051.5 L3890.4277,1051.5 L3890.4277,1049.3418 L3892.8931,1049.3418 L3892.8931,1041.2651 Z "/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacingAndGlyphs" textLength="233" x="3908.5" y="1050.0352">DecodeSelectorFunc func([]byte) Selector</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="3880.5" x2="4143.5" y1="1061.5" y2="1061.5"/><line style="stroke: #A80036; stroke-width: 1.5;" x1="3880.5" x2="4143.5" y1="1069.5" y2="1069.5"/><rect fill="#FEFECE" filter="url(#f1fpjge6j4amxm)" height="96.7969" style="stroke: #A80036; stroke-width: 1.5;" width="346" x="2964" y="1005"/><text fill="#000000" font-family="sans-serif" font-size="12" lengthAdjust="spacingAndGlyphs" textLength="143" x="3065.5" y="1018.6016">Package Public Functions</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="2965" x2="3309" y1="1023.1328" y2="1023.1328"/><text fill="#000000" font-family="sans-serif" font-size="10" lengthAdjust="spacingAndGlyphs" textLength="177" x="2970" y="1036.8008">func FromPBReader(pbr ggio.Reader,</text><text fill="#000000" font-family="sans-serif" font-size="10" lengthAdjust="spacingAndGlyphs" textLength="304" x="2970" y="1048.5781">decodeSelectionResponseFunc: DecodeSelectionResponseFunc,</text><text fill="#000000" font-family="sans-serif" font-size="10" lengthAdjust="spacingAndGlyphs" textLength="334" x="2970" y="1060.3555">decodeSelectorFunc: DecodeSelectorFunc) (GraphSyncMessage, error)</text><text fill="#000000" font-family="sans-serif" font-size="10" lengthAdjust="spacingAndGlyphs" textLength="124" x="2970" y="1072.1328">func FromNet(r io.Reader,</text><text fill="#000000" font-family="sans-serif" font-size="10" lengthAdjust="spacingAndGlyphs" textLength="304" x="2970" y="1083.9102">decodeSelectionResponseFunc: DecodeSelectionResponseFunc,</text><text fill="#000000" font-family="sans-serif" font-size="10" lengthAdjust="spacingAndGlyphs" textLength="334" x="2970" y="1095.6875">decodeSelectorFunc: DecodeSelectorFunc) (GraphSyncMessage, error)</text><!--class GraphSyncRequest--><rect fill="#FEFECE" filter="url(#f1fpjge6j4amxm)" height="112.7754" id="GraphSyncRequest" style="stroke: #A80036; stroke-width: 1.5;" width="140" x="3704" y="997"/><ellipse cx="3719" cy="1013" fill="#B4A7E5" rx="11" ry="11" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M3714.9277,1008.7651 L3714.9277,1006.6069 L3722.3071,1006.6069 L3722.3071,1008.7651 L3719.8418,1008.7651 L3719.8418,1016.8418 L3722.3071,1016.8418 L3722.3071,1019 L3714.9277,1019 L3714.9277,1016.8418 L3717.3931,1016.8418 L3717.3931,1008.7651 Z "/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacingAndGlyphs" textLength="108" x="3733" y="1017.5352">GraphSyncRequest</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="3705" x2="3843" y1="1029" y2="1029"/><line style="stroke: #A80036; stroke-width: 1.5;" x1="3705" x2="3843" y1="1037" y2="1037"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="97" x="3710" y="1051.6348">Selector() Selector</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="66" x="3710" y="1064.5898">Root() Cid</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="89" x="3710" y="1077.5449">Priority() Priority</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="54" x="3710" y="1090.5">ID() int</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="80" x="3710" y="1103.4551">IsCancel() bool</text><!--class GraphSyncResponse--><rect fill="#FEFECE" filter="url(#f1fpjge6j4amxm)" height="73.9102" id="GraphSyncResponse" style="stroke: #A80036; stroke-width: 1.5;" width="149" x="3519.5" y="1016.5"/><ellipse cx="3534.5" cy="1032.5" fill="#B4A7E5" rx="11" ry="11" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M3530.4277,1028.2651 L3530.4277,1026.1069 L3537.8071,1026.1069 L3537.8071,1028.2651 L3535.3418,1028.2651 L3535.3418,1036.3418 L3537.8071,1036.3418 L3537.8071,1038.5 L3530.4277,1038.5 L3530.4277,1036.3418 L3532.8931,1036.3418 L3532.8931,1028.2651 Z "/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacingAndGlyphs" textLength="117" x="3548.5" y="1037.0352">GraphSyncResponse</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="3520.5" x2="3667.5" y1="1048.5" y2="1048.5"/><line style="stroke: #A80036; stroke-width: 1.5;" x1="3520.5" x2="3667.5" y1="1056.5" y2="1056.5"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="79" x="3525.5" y="1071.1348">RequestID() int</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="135" x="3525.5" y="1084.0898">Status() GraphSyncStatus</text><!--class GraphSyncMessage--><rect fill="#FEFECE" filter="url(#f1fpjge6j4amxm)" height="73.9102" id="GraphSyncMessage" style="stroke: #A80036; stroke-width: 1.5;" width="205" x="3491.5" y="1404"/><ellipse cx="3534.4" cy="1420" fill="#B4A7E5" rx="11" ry="11" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M3530.3277,1415.7651 L3530.3277,1413.6069 L3537.7071,1413.6069 L3537.7071,1415.7651 L3535.2418,1415.7651 L3535.2418,1423.8418 L3537.7071,1423.8418 L3537.7071,1426 L3530.3277,1426 L3530.3277,1423.8418 L3532.7931,1423.8418 L3532.7931,1415.7651 Z "/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacingAndGlyphs" textLength="111" x="3554.6" y="1424.5352">GraphSyncMessage</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="3492.5" x2="3695.5" y1="1436" y2="1436"/><line style="stroke: #A80036; stroke-width: 1.5;" x1="3492.5" x2="3695.5" y1="1444" y2="1444"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="175" x="3497.5" y="1458.6348">Requests() : []GraphSyncRequest</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="193" x="3497.5" y="1471.5898">Responses() : []GraphSyncResponse</text><!--class Exportable--><rect fill="#FEFECE" filter="url(#f1fpjge6j4amxm)" height="73.9102" id="Exportable" style="stroke: #A80036; stroke-width: 1.5;" width="139" x="3345.5" y="1016.5"/><ellipse cx="3380.3" cy="1032.5" fill="#B4A7E5" rx="11" ry="11" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M3376.2277,1028.2651 L3376.2277,1026.1069 L3383.6071,1026.1069 L3383.6071,1028.2651 L3381.1418,1028.2651 L3381.1418,1036.3418 L3383.6071,1036.3418 L3383.6071,1038.5 L3376.2277,1038.5 L3376.2277,1036.3418 L3378.6931,1036.3418 L3378.6931,1028.2651 Z "/><text fill="#000000" font-family="sans-serif" font-size="12" font-style="italic" lengthAdjust="spacingAndGlyphs" textLength="63" x="3398.7" y="1037.0352">Exportable</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="3346.5" x2="3483.5" y1="1048.5" y2="1048.5"/><line style="stroke: #A80036; stroke-width: 1.5;" x1="3346.5" x2="3483.5" y1="1056.5" y2="1056.5"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="51" x="3351.5" y="1071.1348">ToProto()</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="127" x="3351.5" y="1084.0898">ToNet(w io.Writer) error</text><!--class go-filecoin--><rect fill="#FEFECE" filter="url(#f1fpjge6j4amxm)" height="112.7754" id="go-filecoin" style="stroke: #A80036; stroke-width: 1.5;" width="349" x="1183.5" y="43"/><ellipse cx="1323.25" cy="59" fill="#ADD1B2" rx="11" ry="11" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M1326.2231,64.6431 Q1325.6421,64.9419 1325.0029,65.0913 Q1324.3638,65.2407 1323.6582,65.2407 Q1321.1514,65.2407 1319.8315,63.5889 Q1318.5117,61.937 1318.5117,58.8159 Q1318.5117,55.6865 1319.8315,54.0347 Q1321.1514,52.3828 1323.6582,52.3828 Q1324.3638,52.3828 1325.0112,52.5322 Q1325.6587,52.6816 1326.2231,52.9805 L1326.2231,55.7031 Q1325.5923,55.1221 1324.9988,54.8523 Q1324.4053,54.5825 1323.7744,54.5825 Q1322.4297,54.5825 1321.7449,55.6492 Q1321.0601,56.7158 1321.0601,58.8159 Q1321.0601,60.9077 1321.7449,61.9744 Q1322.4297,63.041 1323.7744,63.041 Q1324.4053,63.041 1324.9988,62.7712 Q1325.5923,62.5015 1326.2231,61.9204 Z "/><text fill="#000000" font-family="sans-serif" font-size="12" lengthAdjust="spacingAndGlyphs" textLength="61" x="1343.75" y="63.5352">go-filecoin</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="1184.5" x2="1531.5" y1="75" y2="75"/><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="124" x="1189.5" y="89.6348">graphSync : GraphSync</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="174" x="1189.5" y="102.5898">selectorQuerier: SelectorQuerier</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="117" x="1189.5" y="115.5449">host: libp2pHost.Host</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="337" x="1189.5" y="128.5">decodeSelectionResponseFunc: DecodeSelectionResponseFunc</text><text fill="#000000" font-family="sans-serif" font-size="11" lengthAdjust="spacingAndGlyphs" textLength="223" x="1189.5" y="141.4551">decodeSelectorFunc: DecodeSelectorFunc</text><line style="stroke: #A80036; stroke-width: 1.5;" x1="1184.5" x2="1531.5" y1="147.7754" y2="147.7754"/><path d="M832.5,279 L832.5,304.3105 L1099.5,304.3105 L1099.5,289 L1089.5,279 L832.5,279 " fill="#FBFB77" filter="url(#f1fpjge6j4amxm)" style="stroke: #A80036; stroke-width: 1.0;"/><path d="M1089.5,279 L1089.5,289 L1099.5,289 L1089.5,279 " fill="#FBFB77" style="stroke: #A80036; stroke-width: 1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="246" x="838.5" y="296.5684">Is this the right name for this package?</text><!--link GMN5 to go-selector--><path d="M966,304.1843 C966,323.169 966,360.355 966,394.0824 C966,395.1364 966,396.187 966,397.2336 C966,397.7569 966,398.2791 966,398.8003 C966,399.0609 966,399.3212 966,399.5813 " fill="none" id="GMN5-go-selector" style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 7.0,7.0;"/><!--link Node to Selector--><path d="M1323.3466,308.4475 C1271.9877,324.8563 1189.9094,348.9658 1117,361 C901.2623,396.6089 844.28,379.1699 626,392 C609.6707,392.9598 493.7378,392.9031 479,400 C461.1705,408.5858 446.4819,425.5248 436.4831,439.8201 " fill="none" id="Node-Selector" style="stroke: #A80036; stroke-width: 1.0;"/><polygon fill="none" points="1321.2175,301.7792,1342.4016,302.261,1325.5407,315.095,1321.2175,301.7792" style="stroke: #A80036; stroke-width: 1.0;"/><!--link Node to SelectionResponse--><path d="M1375.3204,335.7924 C1373.4106,356.0438 1367.2592,378.4843 1351,392 C1334.4096,405.791 1177.3552,392.8516 1157,400 C1133.2933,408.3254 1110.5677,425.4703 1094.2914,439.9207 " fill="none" id="Node-SelectionResponse" style="stroke: #A80036; stroke-width: 1.0;"/><polygon fill="none" points="1368.3322,335.3239,1376.0136,315.5756,1382.324,335.8038,1368.3322,335.3239" style="stroke: #A80036; stroke-width: 1.0;"/><!--link GraphSync to SelectorQuerier--><path d="M1785.1761,359.4986 C1703.1869,382.4582 1614.7402,407.2262 1544.5406,426.8843 " fill="none" id="GraphSync-SelectorQuerier" style="stroke: #A80036; stroke-width: 1.0;"/><polygon fill="#A80036" points="1797.7483,355.9779,1790.8919,353.7441,1786.1929,359.2139,1793.0493,361.4477,1797.7483,355.9779" style="stroke: #A80036; stroke-width: 1.0;"/><!--link Receiver to GraphSync--><path d="M2502.0186,789.8209 C2536.144,781.2269 2572.6404,773.2262 2607,768 C2650.9926,761.3087 3407,772.9986 3407,728.5 C3407,464 3407,464 3407,464 C3407,337.8133 2400.102,383.8427 2276,361 C2270.0633,359.9073 2264.0631,358.7365 2258.0225,357.499 " fill="none" id="Receiver-GraphSync" style="stroke: #A80036; stroke-width: 1.0;"/><polygon fill="none" points="2503.3494,796.7068,2482.2341,794.9329,2499.8469,783.152,2503.3494,796.7068" style="stroke: #A80036; stroke-width: 1.0;"/><text fill="#000000" font-family="sans-serif" font-size="13" lengthAdjust="spacingAndGlyphs" textLength="71" x="3408" y="622.0684">receiver for</text><!--link GraphSyncNetwork to libP2PGraphSyncNetwork--><path d="M2106.348,872.9787 C2211.8792,894.3402 2316,918.4656 2316,930.5 C2316,930.5 2316,930.5 2316,1171.5 C2316,1209.4393 2558.0465,1237.1025 2693.2521,1249.5954 " fill="none" id="GraphSyncNetwork-libP2PGraphSyncNetwork" style="stroke: #A80036; stroke-width: 1.0;"/><polygon fill="none" points="2104.883,879.8243,2086.6514,869.0257,2107.6378,866.098,2104.883,879.8243" style="stroke: #A80036; stroke-width: 1.0;"/><!--link goGraphSyncNetworkPF to libP2PGraphSyncNetwork--><path d="M2782,862.6144 C2782,882.0581 2782,907.7561 2782,930.5 C2782,930.5 2782,930.5 2782,1171.5 C2782,1192.1328 2782,1215.5664 2782,1232.6764 " fill="none" id="goGraphSyncNetworkPF-libP2PGraphSyncNetwork" style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 7.0,7.0;"/><!--link SelectorQuerier to RequestManager--><path d="M1604.4231,501.0451 C1622.4978,503.9675 1640.5699,506.6798 1658,509 C1779.1375,525.1251 1809.9963,524.9705 1932,532 C1988.6007,535.2612 2131.3408,529.2146 2187,540 C2213.9045,545.2134 2241.9346,553.4042 2268.425,562.5346 " fill="none" id="SelectorQuerier-RequestManager" style="stroke: #A80036; stroke-width: 1.0;"/><polygon fill="#A80036" points="2280.8845,566.9352,2276.5591,561.1653,2269.5695,562.9388,2273.8949,568.7087,2280.8845,566.9352" style="stroke: #A80036; stroke-width: 1.0;"/><!--link RequestManager to GraphSyncNetwork--><path d="M2266.5163,672.1159 C2175.3085,710.6418 2055.9745,761.0481 1975.8958,794.8731 " fill="none" id="RequestManager-GraphSyncNetwork" style="stroke: #A80036; stroke-width: 1.0;"/><polygon fill="#A80036" points="2278.6253,667.0011,2271.5417,665.651,2267.571,671.6704,2274.6546,673.0205,2278.6253,667.0011" style="stroke: #A80036; stroke-width: 1.0;"/><!--link GraphSync to RequestManager--><path d="M2117.2108,370.1941 C2186.6017,431.4048 2280.7788,514.4797 2340.2233,566.9165 " fill="none" id="GraphSync-RequestManager" style="stroke: #A80036; stroke-width: 1.0;"/><polygon fill="#A80036" points="2107.1598,361.3279,2109.0133,368.2967,2116.1589,369.2662,2114.3054,362.2973,2107.1598,361.3279" style="stroke: #A80036; stroke-width: 1.0;"/><!--link SelectorQuerier to ResponseManager--><path d="M1602.719,501.0088 C1621.3573,503.9868 1640.0174,506.72 1658,509 C1800.3362,527.0468 1836.6369,526.3173 1980,532 C2036.0133,534.2203 2934.0949,528.6927 2989,540 C3018.1142,545.9959 3048.38,556.6901 3075.7176,568.2368 " fill="none" id="SelectorQuerier-ResponseManager" style="stroke: #A80036; stroke-width: 1.0;"/><polygon fill="#A80036" points="3087.6485,573.4064,3083.7334,567.3506,3076.6377,568.6354,3080.5528,574.6912,3087.6485,573.4064" style="stroke: #A80036; stroke-width: 1.0;"/><!--link ResponseManager to GraphSyncNetwork--><path d="M3035.0941,664.2113 C3019.6761,668.3837 3004.0884,672.112 2989,675 C2854.2092,700.7994 2817.5829,683.6101 2681,697 C2427.3659,721.8651 2361.7081,717.0646 2112,768 C2076.8292,775.1741 2039.1226,785.0659 2004.8654,794.9289 " fill="none" id="ResponseManager-GraphSyncNetwork" style="stroke: #A80036; stroke-width: 1.0;"/><polygon fill="#A80036" points="3047.9907,660.6107,3041.1361,658.3714,3036.4327,663.8375,3043.2873,666.0768,3047.9907,660.6107" style="stroke: #A80036; stroke-width: 1.0;"/><!--link GraphSync to ResponseManager--><path d="M2271.0603,359.6857 C2272.7124,360.126 2274.3591,360.5642 2276,361 C2591.775,444.868 2679.0823,436.5657 2989,540 C3017.7723,549.6027 3048.3877,561.7022 3076.1792,573.4472 " fill="none" id="GraphSync-ResponseManager" style="stroke: #A80036; stroke-width: 1.0;"/><polygon fill="#A80036" points="2258.2985,356.2694,2263.06,361.685,2269.8903,359.3726,2265.1288,353.9571,2258.2985,356.2694" style="stroke: #A80036; stroke-width: 1.0;"/><!--link goGraphSyncMessagePF to libP2PGraphSyncNetwork--><path d="M3051.9687,1102.2433 C2979.9701,1143.5158 2879.8099,1200.9315 2823.9378,1232.9596 " fill="none" id="goGraphSyncMessagePF-libP2PGraphSyncNetwork" style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 7.0,7.0;"/><!--link Exportable to GraphSyncMessage--><path d="M3451.332,1090.5775 C3468.8004,1112.3192 3486,1141.3752 3486,1171.5 C3486,1171.5 3486,1171.5 3486,1342.5 C3486,1361.0431 3494.7988,1377.0255 3507.3736,1390.3984 " fill="none" id="Exportable-GraphSyncMessage" style="stroke: #A80036; stroke-width: 1.0;"/><polygon fill="none" points="3512.1376,1385.2688,3522.2629,1403.8828,3502.7397,1395.6457,3512.1376,1385.2688" style="stroke: #A80036; stroke-width: 1.0;"/><!--link GraphSyncRequest to GraphSyncMessage--><path d="M3722.8254,1110.1528 C3711.0978,1128.4383 3702,1149.6613 3702,1171.5 C3702,1171.5 3702,1171.5 3702,1342.5 C3702,1363.4103 3690.8112,1381.0644 3675.6364,1395.3922 " fill="none" id="GraphSyncRequest-GraphSyncMessage" style="stroke: #A80036; stroke-width: 1.0;"/><polygon fill="#A80036" points="3665.7371,1403.8828,3672.8955,1403.0127,3674.8456,1396.0703,3667.6872,1396.9404,3665.7371,1403.8828" style="stroke: #A80036; stroke-width: 1.0;"/><!--link GraphSyncResponse to GraphSyncMessage--><path d="M3594,1090.7018 C3594,1113.9308 3594,1144.4583 3594,1171.5 C3594,1171.5 3594,1171.5 3594,1342.5 C3594,1358.1071 3594,1375.1051 3594,1390.5188 " fill="none" id="GraphSyncResponse-GraphSyncMessage" style="stroke: #A80036; stroke-width: 1.0;"/><polygon fill="#A80036" points="3594,1403.5814,3598,1397.5814,3594,1391.5814,3590,1397.5814,3594,1403.5814" style="stroke: #A80036; stroke-width: 1.0;"/><!--link go-filecoin to GraphSync--><path d="M1545.6594,153.277 C1623.8905,175.6955 1715.509,201.9503 1797.7594,225.5206 " fill="none" id="go-filecoin-GraphSync" style="stroke: #A80036; stroke-width: 1.0;"/><polygon fill="#A80036" points="1532.7224,149.5697,1537.3883,155.0678,1544.2581,152.8755,1539.5922,147.3774,1532.7224,149.5697" style="stroke: #A80036; stroke-width: 1.0;"/><!--link go-filecoin to goGraphsyncPf--><path d="M1532.7054,104.7518 C1718.9901,113.3388 2021.5927,135.8936 2276,195 C2356.2669,213.6484 2445.4658,250.0838 2496.3379,272.4594 " fill="none" id="go-filecoin-goGraphsyncPf" style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 7.0,7.0;"/><!--link go-filecoin to goGraphSyncNetworkPF--><path d="M1532.9203,101.5289 C2032.6191,108.0778 3435.529,132.0116 3511,195 C3544.7724,223.1866 3533,247.5107 3533,291.5 C3533,291.5 3533,291.5 3533,728.5 C3533,745.5764 3525.7355,751.3704 3511,760 C3462.9871,788.1181 3139.9548,811.4391 2940.3427,823.382 " fill="none" id="go-filecoin-goGraphSyncNetworkPF" style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 7.0,7.0;"/><!--link go-filecoin to Selector--><path d="M1183.3464,113.496 C1074.6778,126.2453 933.5411,150.2507 815,195 C651.3397,256.7817 613.3015,287.9073 479,400 C464.8354,411.8222 451.0195,427.2073 440.5377,439.93 " fill="none" id="go-filecoin-Selector" style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 7.0,7.0;"/><!--link go-filecoin to SelectorQuerier--><path d="M1323.7909,168.3005 C1320.5953,177.1093 1317.8611,186.145 1316,195 C1300.8249,267.2002 1288.9691,292.3524 1316,361 C1325.9861,386.3606 1345.4846,409.1689 1364.315,426.8373 " fill="none" id="go-filecoin-SelectorQuerier" style="stroke: #A80036; stroke-width: 1.0;"/><polygon fill="#A80036" points="1328.5732,156.0407,1322.6662,160.1769,1324.2123,167.2203,1330.1193,163.0841,1328.5732,156.0407" style="stroke: #A80036; stroke-width: 1.0;"/><!--link go-filecoin to goSelectorPF--><path d="M1183.1841,107.8857 C973.11,119.9498 634.3549,146.3066 518,195 C376.0857,254.3898 245.9501,393.6138 201.3318,444.7346 " fill="none" id="go-filecoin-goSelectorPF" style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 7.0,7.0;"/><!--
@startuml "GraphSync"
package "go-ipld-format" {
interface Node
}
note top of "go-selector"
Is this the right name for this package?
end note
package "go-selector" {
interface Selector {
}
interface SelectionResponse {
}
interface SelectionTraverser {
Next() SelectionResponse, err
Cancel()
}
interface "GetBlockFunc func(cid) block.Block" as GetBlockFunc
interface SelectorQuerier {
Select(Selector, root Cid) SelectionTraverser
Validate(Selector, root Cid, incomingResponses SelectionTraverser) SelectionTraverser
}
object "Package Public Functions" as goSelectorPF {
NewSelectorQuerier(getBlockFunc GetBlockFunc) SelectorQuerier
}
Node <|- - Selector
Node <|- - SelectionResponse
}
package "go-graphsync" {
class GraphSync {
network : GraphySyncNetwork
requestManager : RequestManager
responseManager: ResponseManager
selectorQuerier: SelectorQuerier
Request(p peer.ID, selector Selector, root Cid) SelectionTraverser
ReceiveMessage(ctx context.Context, sender peer.ID, incoming GraphSyncMessage)
ReceiveError(error)
}
GraphSync *- - SelectorQuerier
package network {
interface Receiver {
ReceiveMessage(ctx context.Context, sender peer.ID, incoming GraphSyncMessage)
ReceiveError(error)
}
interface GraphSyncNetwork {
SendMessage(ctx context.Context, receiver peer.Id, m GraphSyncMessage)
SetDelegate(receiver Receiver)
}
Receiver <|- - GraphSync : receiver for
class libP2PGraphSyncNetwork {
}
GraphSyncNetwork <|- - libP2PGraphSyncNetwork
object "Package Public Functions" as goGraphSyncNetworkPF {
NewLibP2PNetwork(host libp2pHost.Host,
decodeSelectionResponseFunc: DecodeSelectionResponseFunc,
decodeSelectorFunc: DecodeSelectorFunc) GraphSyncNetwork
}
goGraphSyncNetworkPF .. libP2PGraphSyncNetwork
}
package requestmanager {
class RequestManager {
network : GraphSyncNetwork
selectorQuerier: SelectorQuerier
SendRequest(p peer.ID, selector Selector, root Cid) SelectionTraverser
ProcessResponses(responses []GraphSyncResponse)
}
SelectorQuerier - -* RequestManager
RequestManager *- - GraphSyncNetwork
GraphSync *- - RequestManager
note as requestManager
The ResponseManager uses Validate from go-selector
to filter incoming Responses based on whether they are valid and produce
a traverser that only returns valid responses
end note
}
package responsemanager {
class ResponseManager {
network : GraphySyncNetwork
selectorQuerier: SelectorQuerier
ProcessRequests(p peer.ID, requests []GraphSyncRequests)
}
SelectorQuerier - -* ResponseManager
ResponseManager *- - GraphSyncNetwork
GraphSync *- - ResponseManager
note as responseManagerNote
The ResponseManager uses Select from go-selector
to translate the raw bytes into a selector and then
traverse the graph to produce a list of blocks
Question: how to know if response is partial?
end note
}
package message {
interface "DecodeSelectionResponseFunc func([]byte) SelectionResponse" as DecodeSelectionResponseFunc
interface "DecodeSelectorFunc func([]byte) Selector" as DecodeSelectorFunc
object "Package Public Functions" as goGraphSyncMessagePF {
func FromPBReader(pbr ggio.Reader,
decodeSelectionResponseFunc: DecodeSelectionResponseFunc,
decodeSelectorFunc: DecodeSelectorFunc) (GraphSyncMessage, error)
func FromNet(r io.Reader,
decodeSelectionResponseFunc: DecodeSelectionResponseFunc,
decodeSelectorFunc: DecodeSelectorFunc) (GraphSyncMessage, error)
}
goGraphSyncMessagePF .. libP2PGraphSyncNetwork
interface GraphSyncRequest {
Selector() Selector
Root() Cid
Priority() Priority
ID() int
IsCancel() bool
}
interface GraphSyncResponse {
RequestID() int
Status() GraphSyncStatus
}
interface GraphSyncMessage {
Requests() : []GraphSyncRequest
Responses() : []GraphSyncResponse
}
interface Exportable {
ToProto()
ToNet(w io.Writer) error
}
Exportable - -|> GraphSyncMessage
GraphSyncRequest - -* GraphSyncMessage
GraphSyncResponse - -* GraphSyncMessage
}
object "PackagePublicFunctions" as goGraphsyncPf {
New(ctx context.Context, network GraphSyncNetwork, selectorQuerier SelectorQuerier) GraphSync
}
}
package "go-filecoin" {
class "go-filecoin" {
graphSync : GraphSync
selectorQuerier: SelectorQuerier
host: libp2pHost.Host
decodeSelectionResponseFunc: DecodeSelectionResponseFunc
decodeSelectorFunc: DecodeSelectorFunc
}
"go-filecoin" *- - GraphSync
"go-filecoin" .. goGraphsyncPf
"go-filecoin" .. goGraphSyncNetworkPF
"go-filecoin" .. Selector
"go-filecoin" *- - SelectorQuerier
"go-filecoin" .. goSelectorPF
}
@enduml
PlantUML version 1.2018.12(Sun Oct 21 03:15:15 PDT 2018)
(GPL source distribution)
Java Runtime: Java(TM) SE Runtime Environment
JVM: Java HotSpot(TM) 64-Bit Server VM
Java Version: 1.8.0_92-b14
Operating System: Mac OS X
OS Version: 10.13.2
Default Encoding: UTF-8
Language: en
Country: US
--></g></svg>
\ No newline at end of file
......@@ -62,6 +62,14 @@ package "go-graphsync" {
interface GraphSyncNetwork {
SendMessage(ctx context.Context, receiver peer.Id, m GraphSyncMessage)
SetDelegate(receiver Receiver)
ConnectTo(ctx context.Context, peer.ID) error
NewMessageSender(context.Context, peer.ID) (MessageSender, error)
}
interface MessageSender {
SendMsg(context.Context, GraphSyncMessage) error
Close() error
Reset() error
}
Receiver <|-- GraphSync : receiver for
......
package network
import (
"context"
gsmsg "github.com/ipfs/go-graphsync/message"
peer "github.com/libp2p/go-libp2p-peer"
protocol "github.com/libp2p/go-libp2p-protocol"
)
var (
// ProtocolGraphsync is the protocol identifier for graphsync messages
ProtocolGraphsync protocol.ID = "/ipfs/graphsync/1.0.0"
)
// GraphSyncNetwork provides network connectivity for GraphSync.
type GraphSyncNetwork interface {
// SendMessage sends a GraphSync message to a peer.
SendMessage(
context.Context,
peer.ID,
gsmsg.GraphSyncMessage) error
// SetDelegate registers the Reciver to handle messages received from the
// network.
SetDelegate(Receiver)
// ConnectTo establishes a connection to the given peer
ConnectTo(context.Context, peer.ID) error
NewMessageSender(context.Context, peer.ID) (MessageSender, error)
}
// MessageSender is an interface to send messages to a peer
type MessageSender interface {
SendMsg(context.Context, gsmsg.GraphSyncMessage) error
Close() error
Reset() error
}
// Receiver is an interface for receiving messages from the GraphSyncNetwork.
type Receiver interface {
ReceiveMessage(
ctx context.Context,
sender peer.ID,
incoming gsmsg.GraphSyncMessage)
ReceiveError(error)
}
package network
import (
"bufio"
"context"
"fmt"
"io"
"time"
gsmsg "github.com/ipfs/go-graphsync/message"
ggio "github.com/gogo/protobuf/io"
logging "github.com/ipfs/go-log"
host "github.com/libp2p/go-libp2p-host"
inet "github.com/libp2p/go-libp2p-net"
peer "github.com/libp2p/go-libp2p-peer"
pstore "github.com/libp2p/go-libp2p-peerstore"
)
var log = logging.Logger("graphsync_network")
var sendMessageTimeout = time.Minute * 10
// NewFromLibp2pHost returns a GraphSyncNetwork supported by underlying Libp2p host.
func NewFromLibp2pHost(host host.Host,
decodeSelectorFunc gsmsg.DecodeSelectorFunc,
decodeSelectionResponseFunc gsmsg.DecodeSelectionResponseFunc) GraphSyncNetwork {
graphSyncNetwork := libp2pGraphSyncNetwork{
host: host,
decodeSelectorFunc: decodeSelectorFunc,
decodeSelectionResponseFunc: decodeSelectionResponseFunc,
}
host.SetStreamHandler(ProtocolGraphsync, graphSyncNetwork.handleNewStream)
return &graphSyncNetwork
}
// libp2pGraphSyncNetwork transforms the libp2p host interface, which sends and receives
// NetMessage objects, into the graphsync network interface.
type libp2pGraphSyncNetwork struct {
host host.Host
decodeSelectionResponseFunc gsmsg.DecodeSelectionResponseFunc
decodeSelectorFunc gsmsg.DecodeSelectorFunc
// inbound messages from the network are forwarded to the receiver
receiver Receiver
}
type streamMessageSender struct {
s inet.Stream
}
func (s *streamMessageSender) Close() error {
return inet.FullClose(s.s)
}
func (s *streamMessageSender) Reset() error {
return s.s.Reset()
}
func (s *streamMessageSender) SendMsg(ctx context.Context, msg gsmsg.GraphSyncMessage) error {
return msgToStream(ctx, s.s, msg)
}
func msgToStream(ctx context.Context, s inet.Stream, msg gsmsg.GraphSyncMessage) error {
deadline := time.Now().Add(sendMessageTimeout)
if dl, ok := ctx.Deadline(); ok {
deadline = dl
}
if err := s.SetWriteDeadline(deadline); err != nil {
log.Warningf("error setting deadline: %s", err)
}
w := bufio.NewWriter(s)
switch s.Protocol() {
case ProtocolGraphsync:
if err := msg.ToNet(w); err != nil {
log.Debugf("error: %s", err)
return err
}
default:
return fmt.Errorf("unrecognized protocol on remote: %s", s.Protocol())
}
if err := w.Flush(); err != nil {
log.Debugf("error: %s", err)
return err
}
if err := s.SetWriteDeadline(time.Time{}); err != nil {
log.Warningf("error resetting deadline: %s", err)
}
return nil
}
func (gsnet *libp2pGraphSyncNetwork) NewMessageSender(ctx context.Context, p peer.ID) (MessageSender, error) {
s, err := gsnet.newStreamToPeer(ctx, p)
if err != nil {
return nil, err
}
return &streamMessageSender{s: s}, nil
}
func (gsnet *libp2pGraphSyncNetwork) newStreamToPeer(ctx context.Context, p peer.ID) (inet.Stream, error) {
return gsnet.host.NewStream(ctx, p, ProtocolGraphsync)
}
func (gsnet *libp2pGraphSyncNetwork) SendMessage(
ctx context.Context,
p peer.ID,
outgoing gsmsg.GraphSyncMessage) error {
s, err := gsnet.newStreamToPeer(ctx, p)
if err != nil {
return err
}
if err = msgToStream(ctx, s, outgoing); err != nil {
s.Reset()
return err
}
// TODO(https://github.com/libp2p/go-libp2p-net/issues/28): Avoid this goroutine.
go inet.AwaitEOF(s)
return s.Close()
}
func (gsnet *libp2pGraphSyncNetwork) SetDelegate(r Receiver) {
gsnet.receiver = r
}
func (gsnet *libp2pGraphSyncNetwork) ConnectTo(ctx context.Context, p peer.ID) error {
return gsnet.host.Connect(ctx, pstore.PeerInfo{ID: p})
}
// handleNewStream receives a new stream from the network.
func (gsnet *libp2pGraphSyncNetwork) handleNewStream(s inet.Stream) {
defer s.Close()
if gsnet.receiver == nil {
s.Reset()
return
}
reader := ggio.NewDelimitedReader(s, inet.MessageSizeMax)
for {
received, err := gsmsg.FromPBReader(reader,
gsnet.decodeSelectorFunc,
gsnet.decodeSelectionResponseFunc)
if err != nil {
if err != io.EOF {
s.Reset()
go gsnet.receiver.ReceiveError(err)
log.Debugf("graphsync net handleNewStream from %s error: %s", s.Conn().RemotePeer(), err)
}
return
}
p := s.Conn().RemotePeer()
ctx := context.Background()
log.Debugf("graphsync net handleNewStream from %s", s.Conn().RemotePeer())
gsnet.receiver.ReceiveMessage(ctx, p, received)
}
}
package network
import (
"context"
"math/rand"
"reflect"
"testing"
"time"
gsmsg "github.com/ipfs/go-graphsync/message"
"github.com/ipfs/go-graphsync/testselector"
"github.com/libp2p/go-libp2p-peer"
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
)
// Receiver is an interface for receiving messages from the GraphSyncNetwork.
type receiver struct {
messageReceived chan struct{}
lastMessage gsmsg.GraphSyncMessage
lastSender peer.ID
}
func (r *receiver) ReceiveMessage(
ctx context.Context,
sender peer.ID,
incoming gsmsg.GraphSyncMessage) {
r.lastSender = sender
r.lastMessage = incoming
select {
case <-ctx.Done():
case r.messageReceived <- struct{}{}:
}
}
func (r *receiver) ReceiveError(err error) {
}
func TestMessageSendAndReceive(t *testing.T) {
// create network
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
mn := mocknet.New(ctx)
host1, err := mn.GenPeer()
if err != nil {
t.Fatal("error generating host")
}
host2, err := mn.GenPeer()
if err != nil {
t.Fatal("error generating host")
}
err = mn.LinkAll()
if err != nil {
t.Fatal("error linking hosts")
}
gsnet1 := NewFromLibp2pHost(host1,
testselector.MockDecodeSelectorFunc,
testselector.MockDecodeSelectionResponseFunc)
gsnet2 := NewFromLibp2pHost(host2,
testselector.MockDecodeSelectorFunc,
testselector.MockDecodeSelectionResponseFunc)
r := &receiver{
messageReceived: make(chan struct{}),
}
gsnet1.SetDelegate(r)
gsnet2.SetDelegate(r)
selector := testselector.GenerateSelector()
root := testselector.GenerateRootCid()
selectionResponse := testselector.GenerateSelectionResponse()
id := gsmsg.GraphSyncRequestID(rand.Int31())
priority := gsmsg.GraphSyncPriority(rand.Int31())
status := gsmsg.RequestAcknowledged
sent := gsmsg.New()
sent.AddRequest(id, selector, root, priority)
sent.AddResponse(id, status, selectionResponse)
err = gsnet1.ConnectTo(ctx, host2.ID())
if err != nil {
t.Fatal("Unable to connect peers")
}
gsnet1.SendMessage(ctx, host2.ID(), sent)
select {
case <-ctx.Done():
t.Fatal("did not receive message sent")
case <-r.messageReceived:
}
sender := r.lastSender
if sender != host1.ID() {
t.Fatal("received message from wrong node")
}
received := r.lastMessage
sentRequests := sent.Requests()
if len(sentRequests) != 1 {
t.Fatal("Did not add request to sent message")
}
sentRequest := sentRequests[0]
receivedRequests := received.Requests()
if len(receivedRequests) != 1 {
t.Fatal("Did not add request to received message")
}
receivedRequest := receivedRequests[0]
if receivedRequest.ID() != sentRequest.ID() ||
receivedRequest.IsCancel() != sentRequest.IsCancel() ||
receivedRequest.Priority() != sentRequest.Priority() ||
!reflect.DeepEqual(receivedRequest.Root(), sentRequest.Root()) ||
!reflect.DeepEqual(receivedRequest.Selector(), sentRequest.Selector()) {
t.Fatal("Sent message requests did not match received message requests")
}
sentResponses := sent.Responses()
if len(sentResponses) != 1 {
t.Fatal("Did not add response to sent message")
}
sentResponse := sentResponses[0]
receivedResponses := received.Responses()
if len(receivedResponses) != 1 {
t.Fatal("Did not add response to received message")
}
receivedResponse := receivedResponses[0]
if receivedResponse.RequestID() != sentResponse.RequestID() ||
receivedResponse.Status() != sentResponse.Status() ||
!reflect.DeepEqual(receivedResponse.Response(), sentResponse.Response()) {
t.Fatal("Sent message responses did not match received message responses")
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment