<svg viewBox="0 0 780 420" xmlns="http://www.w3.org/2000/svg">
  <defs>
    <marker id="arr" markerWidth="6" markerHeight="4" refX="6" refY="2" orient="auto">
      <polygon points="0 0, 6 2, 0 4" fill="#6366f1"/>
    </marker>
    <marker id="arr-r" markerWidth="6" markerHeight="4" refX="6" refY="2" orient="auto">
      <polygon points="0 0, 6 2, 0 4" fill="#ef4444"/>
    </marker>
    <marker id="arr-a" markerWidth="6" markerHeight="4" refX="6" refY="2" orient="auto">
      <polygon points="0 0, 6 2, 0 4" fill="#d97706"/>
    </marker>
  </defs>

  <!-- Title -->
  <text x="390" y="18" text-anchor="middle" font-family="'Space Mono', monospace" font-size="12" fill="#6366f1">Iroh Connection Filter Pipeline</text>

  <!-- Incoming box -->
  <rect x="300" y="30" width="180" height="36" rx="5" fill="none" stroke="#6366f1" stroke-width="1.5"/>
  <text x="390" y="53" text-anchor="middle" font-family="'Space Mono', monospace" font-size="11" fill="#6366f1">Incoming</text>

  <!-- Branch: UDP vs Relay -->
  <line x1="340" y1="66" x2="220" y2="94" stroke="#6366f1" stroke-width="1" marker-end="url(#arr)"/>
  <line x1="440" y1="66" x2="560" y2="94" stroke="#6366f1" stroke-width="1" marker-end="url(#arr)"/>
  <text x="260" y="78" text-anchor="middle" font-family="'Space Mono', monospace" font-size="8" fill="#888">UDP</text>
  <text x="520" y="78" text-anchor="middle" font-family="'Space Mono', monospace" font-size="8" fill="#888">Relay</text>

  <!-- accept_addr box (left branch) -->
  <rect x="100" y="97" width="240" height="36" rx="5" fill="none" stroke="#d97706" stroke-width="1.5"/>
  <text x="220" y="119" text-anchor="middle" font-family="'Space Mono', monospace" font-size="9" fill="#d97706">accept_addr(addr, validated)</text>

  <!-- accept_endpoint_id box (right branch) -->
  <rect x="440" y="97" width="240" height="36" rx="5" fill="none" stroke="#d97706" stroke-width="1.5"/>
  <text x="560" y="119" text-anchor="middle" font-family="'Space Mono', monospace" font-size="9" fill="#d97706">accept_endpoint_id(id, validated)</text>

  <!-- Rejection arrows from accept_addr -->
  <!-- Retry -->
  <line x1="100" y1="109" x2="50" y2="109" stroke="#d97706" stroke-width="1" marker-end="url(#arr-a)"/>
  <text x="50" y="101" font-family="'Space Mono', monospace" font-size="7" fill="#d97706">Retry</text>

  <!-- Reject -->
  <line x1="100" y1="121" x2="50" y2="134" stroke="#ef4444" stroke-width="1" marker-end="url(#arr-r)"/>
  <text x="50" y="144" font-family="'Space Mono', monospace" font-size="7" fill="#ef4444">Reject / Ignore</text>

  <!-- Rejection arrows from accept_endpoint_id -->
  <!-- Retry -->
  <line x1="680" y1="109" x2="730" y2="109" stroke="#d97706" stroke-width="1" marker-end="url(#arr-a)"/>
  <text x="688" y="101" font-family="'Space Mono', monospace" font-size="7" fill="#d97706">Retry</text>

  <!-- Reject -->
  <line x1="680" y1="121" x2="730" y2="134" stroke="#ef4444" stroke-width="1" marker-end="url(#arr-r)"/>
  <text x="688" y="144" font-family="'Space Mono', monospace" font-size="7" fill="#ef4444">Reject / Ignore</text>

  <!-- Retry loop arrow (right side) -->
  <path d="M 730 113 L 730 42 L 482 42" fill="none" stroke="#d97706" stroke-width="1" marker-end="url(#arr-a)" stroke-dasharray="4 3"/>
  <text x="620" y="36" font-family="'Space Mono', monospace" font-size="7" fill="#d97706">validated=true</text>

  <!-- Accept arrows down from both -->
  <line x1="220" y1="133" x2="220" y2="158" stroke="#6366f1" stroke-width="1" marker-end="url(#arr)"/>
  <text x="236" y="152" font-family="'Space Mono', monospace" font-size="7" fill="#6366f1">Accept</text>
  <line x1="560" y1="133" x2="560" y2="158" stroke="#6366f1" stroke-width="1" marker-end="url(#arr)"/>
  <text x="576" y="152" font-family="'Space Mono', monospace" font-size="7" fill="#6366f1">Accept</text>

  <!-- Retry loop arrow -->
  <path d="M 50 113 L 50 42 L 298 42" fill="none" stroke="#d97706" stroke-width="1" marker-end="url(#arr-a)" stroke-dasharray="4 3"/>
  <text x="120" y="36" font-family="'Space Mono', monospace" font-size="7" fill="#d97706">validated=true</text>

  <!-- Merge into accept_alpn -->
  <line x1="220" y1="158" x2="350" y2="183" stroke="#6366f1" stroke-width="1"/>
  <line x1="560" y1="158" x2="430" y2="183" stroke="#6366f1" stroke-width="1"/>

  <!-- accept_alpn box -->
  <rect x="260" y="183" width="260" height="36" rx="5" fill="none" stroke="#d97706" stroke-width="1.5"/>
  <text x="390" y="205" text-anchor="middle" font-family="'Space Mono', monospace" font-size="9" fill="#d97706">accept_alpn(alpn)</text>

  <!-- Rejection arrow from accept_alpn -->
  <line x1="520" y1="201" x2="600" y2="201" stroke="#ef4444" stroke-width="1" marker-end="url(#arr-r)"/>
  <text x="608" y="205" font-family="'Space Mono', monospace" font-size="7" fill="#ef4444">Reject / Ignore</text>

  <!-- Accept arrow down from accept_alpn -->
  <line x1="390" y1="219" x2="390" y2="249" stroke="#6366f1" stroke-width="1" marker-end="url(#arr)"/>
  <text x="410" y="239" font-family="'Space Mono', monospace" font-size="7" fill="#6366f1">Accept</text>

  <!-- Accepting box -->
  <rect x="300" y="252" width="180" height="40" rx="5" fill="none" stroke="#6366f1" stroke-width="1.5"/>
  <text x="390" y="269" text-anchor="middle" font-family="'Space Mono', monospace" font-size="11" fill="#6366f1">Accepting</text>
  <text x="390" y="285" text-anchor="middle" font-family="'Space Mono', monospace" font-size="7" fill="#888">TLS handshake</text>

  <!-- Arrow down to Connection -->
  <line x1="390" y1="292" x2="390" y2="322" stroke="#6366f1" stroke-width="1" marker-end="url(#arr)"/>

  <!-- Connection box -->
  <rect x="300" y="325" width="180" height="40" rx="5" fill="none" stroke="#6366f1" stroke-width="1.5"/>
  <text x="390" y="343" text-anchor="middle" font-family="'Space Mono', monospace" font-size="11" fill="#6366f1">Connection</text>
  <text x="390" y="356" text-anchor="middle" font-family="'Space Mono', monospace" font-size="7" fill="#888">protocol handler</text>

  <!-- Legend -->
  <line x1="220" y1="400" x2="240" y2="400" stroke="#6366f1" stroke-width="1"/>
  <text x="248" y="403" font-family="'Space Mono', monospace" font-size="7" fill="#888">accept</text>
  <line x1="310" y1="400" x2="330" y2="400" stroke="#d97706" stroke-width="1"/>
  <text x="338" y="403" font-family="'Space Mono', monospace" font-size="7" fill="#888">filter hook</text>
  <line x1="410" y1="400" x2="430" y2="400" stroke="#ef4444" stroke-width="1"/>
  <text x="438" y="403" font-family="'Space Mono', monospace" font-size="7" fill="#888">reject</text>
</svg>
