class Ciri::P2P::DialScheduler

DialScheduler establish outoging connections

Public Class Methods

new(network_state, dialer, dial_outgoing_interval_secs: 15) click to toggle source
# File lib/ciri/p2p/dial_scheduler.rb, line 36
def initialize(network_state, dialer, dial_outgoing_interval_secs: 15)
  @network_state = network_state
  @dialer = dialer
  @dial_outgoing_interval_secs = dial_outgoing_interval_secs
end

Public Instance Methods

run(task: Async::Task.current) click to toggle source
# File lib/ciri/p2p/dial_scheduler.rb, line 42
def run(task: Async::Task.current)
  dial_bootnodes
  # dial outgoing peers every 15 seconds
  task.reactor.every(@dial_outgoing_interval_secs) do
    task.async do
      schedule_dialing_tasks
    end
  end
end

Private Instance Methods

dial_bootnodes() click to toggle source
# File lib/ciri/p2p/dial_scheduler.rb, line 54
def dial_bootnodes
  @network_state.peer_store.find_bootnodes(@network_state.number_of_attemp_outgoing).each do |node|
    conn, handshake = @dialer.dial(node)
    @network_state.new_peer_connected(conn, handshake, direction: Peer::OUTGOING)
  end
end
schedule_dialing_tasks() click to toggle source
# File lib/ciri/p2p/dial_scheduler.rb, line 61
def schedule_dialing_tasks
  @network_state.peer_store.find_attempt_peers(@network_state.number_of_attemp_outgoing).each do |node|
    # avoid dial self or connected peers
    next if @network_state.peers.include?(node.raw_node_id) || node.raw_node_id == @network_state.local_node_id
    conn, handshake = @dialer.dial(node)
    @network_state.new_peer_connected(conn, handshake, direction: Peer::OUTGOING)
  end
end