ciri-p2p 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/ciri/p2p/discovery/service.rb +1 -1
- data/lib/ciri/p2p/network_state.rb +5 -4
- data/lib/ciri/p2p/protocol_context.rb +19 -1
- data/lib/ciri/p2p/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 812787a199fb23a823439aa870a3c80c33f8acc6522b2e3bb5cc7f5993bf8afa
         | 
| 4 | 
            +
              data.tar.gz: 945d1e1e5cde2adc55e3d6cd9e3c7ad214712325499417e222fb520bd644d1e1
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 9b5011a0fb16a3c1937a60b8f7cc7e5a9665ab33b425333dc1c0334eb2ac8b895f4151ffc6682918952440412e3ce7fba9975aaa4675d3b23d9b43f6529afc5b
         | 
| 7 | 
            +
              data.tar.gz: 3900551a9e53ecc7504f99c535201ba1431072d36bb383212959f14e6b8f9bbb68ff8126b8c19e4a872054af2d4e8a7f7837e468776d995215028bacd7bde1b5
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
| @@ -94,7 +94,7 @@ module Ciri | |
| 94 94 | 
             
                          @udp_port = @local_address.ip_port
         | 
| 95 95 | 
             
                        end
         | 
| 96 96 |  | 
| 97 | 
            -
                         | 
| 97 | 
            +
                        info "start discovery server on udp_port: #{@udp_port} tcp_port: #{@tcp_port}\nlocal_node_id: #{@local_node_id}"
         | 
| 98 98 |  | 
| 99 99 | 
             
                        loop do
         | 
| 100 100 | 
             
                          # read discovery message
         | 
| @@ -53,7 +53,7 @@ module Ciri | |
| 53 53 | 
             
                  def initialize_protocols(task: Async::Task.current)
         | 
| 54 54 | 
             
                    # initialize protocols
         | 
| 55 55 | 
             
                    @protocols.each do |protocol|
         | 
| 56 | 
            -
                      context = ProtocolContext.new(self)
         | 
| 56 | 
            +
                      context = ProtocolContext.new(self, protocol: protocol)
         | 
| 57 57 | 
             
                      task.async {protocol.initialized(context)}
         | 
| 58 58 | 
             
                    end
         | 
| 59 59 | 
             
                  end
         | 
| @@ -75,7 +75,7 @@ module Ciri | |
| 75 75 | 
             
                      # check peers
         | 
| 76 76 | 
             
                      protocol_handshake_checks(handshake)
         | 
| 77 77 | 
             
                      @peers[peer.raw_node_id] = peer
         | 
| 78 | 
            -
                       | 
| 78 | 
            +
                      info "[#{local_node_id.short_hex}] connect to new peer #{peer.inspect}"
         | 
| 79 79 | 
             
                      @peer_store.update_peer_status(peer.raw_node_id, PeerStore::Status::CONNECTED)
         | 
| 80 80 | 
             
                      # run peer logic
         | 
| 81 81 | 
             
                      task.async do
         | 
| @@ -89,7 +89,7 @@ module Ciri | |
| 89 89 | 
             
                    @peers_lock.acquire do
         | 
| 90 90 | 
             
                      # only disconnect from peers if direction correct to avoiding delete peer by mistake
         | 
| 91 91 | 
             
                      if (exist_peer = @peers[peer.raw_node_id]) && exist_peer.direction == peer.direction
         | 
| 92 | 
            -
                         | 
| 92 | 
            +
                        info("[#{local_node_id.short_hex}] disconnect peer: #{peer.inspect}, reason: #{reason}")
         | 
| 93 93 | 
             
                        remove_peer(peer)
         | 
| 94 94 | 
             
                        peer.disconnect
         | 
| 95 95 | 
             
                        @peer_store.update_peer_status(peer.raw_node_id, PeerStore::Status::DISCONNECTED)
         | 
| @@ -166,7 +166,8 @@ module Ciri | |
| 166 166 | 
             
                        handle_message(peer, msg)
         | 
| 167 167 | 
             
                      end
         | 
| 168 168 | 
             
                    rescue StandardError => e
         | 
| 169 | 
            -
                      disconnect_peer(peer, reason: "io error: #{e} | 
| 169 | 
            +
                      disconnect_peer(peer, reason: "io error: #{e}")
         | 
| 170 | 
            +
                      error("io error: #{e}\n#{e.backtrace.join "\n"}")
         | 
| 170 171 | 
             
                    end
         | 
| 171 172 |  | 
| 172 173 | 
             
                    message_service.wait
         | 
| @@ -34,7 +34,6 @@ module Ciri | |
| 34 34 |  | 
| 35 35 | 
             
                  attr_reader :peer, :protocol, :protocol_io
         | 
| 36 36 |  | 
| 37 | 
            -
                  def_delegators :protocol_io, :send_data
         | 
| 38 37 | 
             
                  def_delegators :@network_state, :local_node_id
         | 
| 39 38 |  | 
| 40 39 | 
             
                  def initialize(network_state, peer: nil, protocol: nil, protocol_io: nil)
         | 
| @@ -44,9 +43,28 @@ module Ciri | |
| 44 43 | 
             
                    @protocol_io = protocol_io
         | 
| 45 44 | 
             
                  end
         | 
| 46 45 |  | 
| 46 | 
            +
                  def send_data(code, data, peer: self.peer, protocol: self.protocol.name)
         | 
| 47 | 
            +
                    ensure_peer(peer).find_protocol_io(protocol).send_data(code, data)
         | 
| 48 | 
            +
                  end
         | 
| 49 | 
            +
             | 
| 47 50 | 
             
                  def raw_local_node_id
         | 
| 48 51 | 
             
                    @raw_local_node_id ||= local_node_id.to_bytes
         | 
| 49 52 | 
             
                  end
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                  def peers
         | 
| 55 | 
            +
                    @network_state.peers.values
         | 
| 56 | 
            +
                  end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                  def find_peer(raw_node_id)
         | 
| 59 | 
            +
                    @network_state.peers[raw_node_id]
         | 
| 60 | 
            +
                  end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                  private
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                  def ensure_peer(peer)
         | 
| 65 | 
            +
                    return peer if peer.is_a?(P2P::Peer)
         | 
| 66 | 
            +
                    @network_state.peers[peer]
         | 
| 67 | 
            +
                  end
         | 
| 50 68 | 
             
                end
         | 
| 51 69 |  | 
| 52 70 | 
             
              end
         | 
    
        data/lib/ciri/p2p/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: ciri-p2p
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.3.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - jjy
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: exe
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2018-11- | 
| 11 | 
            +
            date: 2018-11-26 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: ciri-utils
         |