@startuml

start

:relay_as_entry = True;
if (consensus has `cc_alg=2`) then (yes)
  if (consensus has `bwscanner_cc>=1`) then (yes)
    if (relay to measure is exit AND has `FlowCtrl=2`) then (yes)
      :relay_as_entry = False;
    endif
  'no bwscanner>=1
  else (no)
    if (relay to measure is exit AND has NOT `FlowCtrl=2`) then (yes)
      :relay_as_entry = False;
    endif
  endif
' no cc_alg=2
else (no)
  if (relay to measure is exit?) then (yes)
      :relay_as_entry = False;
  endif
endif


if (consensus has `cc_alg=2`) then (yes)
  if (consensus has `bwscanner_cc>=1`) then (yes)
    if (relay to measure is exit AND has `FlowCtrl=2` AND NOT relay_as_entry) then (yes)
      :obtain non-exits;
    else (no)
      :obtain exits
      with proto `FlowCtrol=2`
      without bad flag
      that can exit
      to port 443;
    endif
  'no bwscanner>=1
  else (no)
    if (relay to measure is exit AND has NOT `FlowCtrl=2` AND NOT relay_as_entry) then (yes)
      :obtain non-exits;
    else (no)
      :obtain exits
      with proto `FlowCtrol!=2`
      without bad flag
      that can exit
      to port 443;
    endif
  endif
' no cc_alg=2
else (no)
  if (relay to measure is exit AND NOT relay_as_entry?) then (yes)
    :obtain non-exits;
  else (no)
    :obtain exits
    without bad flag
    that can exit
    to port 443;
  endif
endif


:potential second relays;
:obtain a relay
from potential
sencond relays
randomly;
if (second relay has 2x bandwidth?) then (yes)
elseif (other second relay has 1.5x bandwidth?) then (yes)
elseif (other second relay has 1x bandwidth?) then (yes)
else (nothing)
  stop
endif
:second relay selected!;
:Build a circuit
whith exit as
second hop;
stop

@enduml
