ciri-p2p 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84a78196ee2a9a850e3f893c8f3f7a4a30eae83eb9cde69537020215723b9a8e
4
- data.tar.gz: '09e75872015ea1b557150db5650f4ef2ccd7bcd180b6fbfa2caa78eae705a769'
3
+ metadata.gz: 812787a199fb23a823439aa870a3c80c33f8acc6522b2e3bb5cc7f5993bf8afa
4
+ data.tar.gz: 945d1e1e5cde2adc55e3d6cd9e3c7ad214712325499417e222fb520bd644d1e1
5
5
  SHA512:
6
- metadata.gz: adb6135d935ee3ec9e4aa77c65a0aa44d741481acc44b30d6c880f6a9e35732243fdb9e318fee7a99efaab4d3370c3bfdb31d1a9d3bd2a2729e74a501f3b1b4a
7
- data.tar.gz: ce7fcafe49551d9a0cbb9d62496395524d21507053f48add1f9d06101ee123930e2d09d6c082b0c671f3edeb46fe4fd37832513b6c9198fb45e15ff760ecee05
6
+ metadata.gz: 9b5011a0fb16a3c1937a60b8f7cc7e5a9665ab33b425333dc1c0334eb2ac8b895f4151ffc6682918952440412e3ce7fba9975aaa4675d3b23d9b43f6529afc5b
7
+ data.tar.gz: 3900551a9e53ecc7504f99c535201ba1431072d36bb383212959f14e6b8f9bbb68ff8126b8c19e4a872054af2d4e8a7f7837e468776d995215028bacd7bde1b5
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ciri-p2p (0.2.0)
4
+ ciri-p2p (0.3.0)
5
5
  async (~> 1.10.3)
6
6
  async-io (~> 1.15.5)
7
7
  ciri-common (~> 0.1.0)
@@ -94,7 +94,7 @@ module Ciri
94
94
  @udp_port = @local_address.ip_port
95
95
  end
96
96
 
97
- debug "start discovery server on udp_port: #{@udp_port} tcp_port: #{@tcp_port}\nlocal_node_id: #{@local_node_id}"
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
- debug "[#{local_node_id.short_hex}] connect to new peer #{peer.inspect}"
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
- debug("[#{local_node_id.short_hex}] disconnect peer: #{peer.inspect}, reason: #{reason}")
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}\n#{e.backtrace.join "\n"}")
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
@@ -1,6 +1,6 @@
1
1
  module Ciri
2
2
  module P2P
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
6
6
 
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.2.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-17 00:00:00.000000000 Z
11
+ date: 2018-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ciri-utils