Sha256: aa19f04ba626234d8d2929518dd33ad4438b181474f34f5a25b01d2c40f4b72b

Contents?: true

Size: 715 Bytes

Versions: 1

Compression:

Stored size: 715 Bytes

Contents

module Aggro
  # Public: Represents an aggro server node.
  class Node < Struct.new(:id, :endpoint)
    def client
      @client ||= Aggro::Client.new(endpoint)
    end

    def publisher_endpoint
      @publisher_endpoint ||= discover_publisher_endpoint
    end

    def to_s
      id
    end

    private

    def discover_publisher_endpoint
      message = Message::PublisherEndpointInquiry.new(Aggro.local_node.id)
      response = client.post(message)

      if response.is_a? Message::Endpoint
        port = URI.parse(response.endpoint).port

        URI.parse(endpoint).tap { |uri| uri.port = port }.to_s
      else
        fail "Could not discover publisher endpoint for #{id}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aggro-0.0.4 lib/aggro/node.rb