Hearch 2018.8.28

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4929a505b5a640e52533103964b1861bb2fc7438
4
+ data.tar.gz: e3975cc85818341fbd2bd3b4860ec7b35fcb4669
5
+ SHA512:
6
+ metadata.gz: a913769d94d92e545759fbd4b2580b28b9b23d16be2c696ac20d220b87a2cea95077eb471322346d7ae22cbcab4cfe2027f7ea5706bdee776c6d985b9d4f054b
7
+ data.tar.gz: 22f391288f8801d7e189bf6707db940eb1e28d186cfaf93a585c3be7681486ff4c019de84e36a96e2d8c83d712494ce81018807cc792109bf1495ff11f48e4ae
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'Hearch/ExistMessage_pb'
4
+ require 'Hearch/MulticastHandler'
5
+
6
+ class Hearch
7
+ def initialize
8
+ host = '239.173.40.5' #组播组主机地址。
9
+ port = 11500 #组播组端口。
10
+
11
+ @networkThread = EM::open_datagram_socket(host, port, MulticastHandler)
12
+ end
13
+
14
+ # Publish a service to the LAN.
15
+ #
16
+ # Example:
17
+ # >> existRuby=ExistRuby.new
18
+ # >> existRuby.publishService("fp_serverPython", 10086, exist::ServicePublishMessage::ServiceProtocolType::GRPC)
19
+ #
20
+ # Arguments:
21
+ # lanServiceName: (String)
22
+ # lanServicePort: (int)
23
+ # lanServiceProtocolType: (enum)
24
+ def publishService(lanServiceName, lanServicePort, lanServiceProtocolType)
25
+ existMessage=Com::Stupidbeauty::Exist::ExistMessage.new #消息体。
26
+
27
+ existMessage.messageType= Com::Stupidbeauty::Exist::ExistMessage::MessageType::SERVICEPUBLISH #设置消息类型。
28
+
29
+ existMessage.servicePublishMessage=Com::Stupidbeauty::Exist::ServicePublishMessage.new #创建服务发布消息体。
30
+
31
+ existMessage.servicePublishMessage.name=lanServiceName #设置服务名字。
32
+ existMessage.servicePublishMessage.port=lanServicePort #设置端口号。
33
+ existMessage.servicePublishMessage.protocolType=lanServiceProtocolType #设置协议类型。
34
+
35
+ packageString=Com::Stupidbeauty::Exist::ExistMessage.encode(existMessage) #序列化为字符串。
36
+
37
+ #发送:
38
+ @networkThread.castData(packageString) #发送数据。
39
+ end
40
+ end
@@ -0,0 +1,43 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: ExistMessage.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_message "com.stupidbeauty.exist.ServicePublishMessage" do
8
+ optional :name, :string, 1
9
+ optional :port, :int32, 2
10
+ optional :protocolType, :enum, 3, "com.stupidbeauty.exist.ServicePublishMessage.ServiceProtocolType"
11
+ end
12
+ add_enum "com.stupidbeauty.exist.ServicePublishMessage.ServiceProtocolType" do
13
+ value :HTTP, 0
14
+ value :UDP, 1
15
+ value :MQTT, 2
16
+ value :TCP, 3
17
+ value :GRPC, 4
18
+ end
19
+ add_message "com.stupidbeauty.exist.ServiceProbeMessage" do
20
+ optional :port, :int32, 1
21
+ end
22
+ add_message "com.stupidbeauty.exist.ExistMessage" do
23
+ optional :messageType, :enum, 1, "com.stupidbeauty.exist.ExistMessage.MessageType"
24
+ optional :servicePublishMessage, :message, 2, "com.stupidbeauty.exist.ServicePublishMessage"
25
+ optional :serviceProbeMessage, :message, 3, "com.stupidbeauty.exist.ServiceProbeMessage"
26
+ end
27
+ add_enum "com.stupidbeauty.exist.ExistMessage.MessageType" do
28
+ value :SERVICEPUBLISH, 0
29
+ value :SERVICEPROBE, 1
30
+ end
31
+ end
32
+
33
+ module Com
34
+ module Stupidbeauty
35
+ module Exist
36
+ ServicePublishMessage = Google::Protobuf::DescriptorPool.generated_pool.lookup("com.stupidbeauty.exist.ServicePublishMessage").msgclass
37
+ ServicePublishMessage::ServiceProtocolType = Google::Protobuf::DescriptorPool.generated_pool.lookup("com.stupidbeauty.exist.ServicePublishMessage.ServiceProtocolType").enummodule
38
+ ServiceProbeMessage = Google::Protobuf::DescriptorPool.generated_pool.lookup("com.stupidbeauty.exist.ServiceProbeMessage").msgclass
39
+ ExistMessage = Google::Protobuf::DescriptorPool.generated_pool.lookup("com.stupidbeauty.exist.ExistMessage").msgclass
40
+ ExistMessage::MessageType = Google::Protobuf::DescriptorPool.generated_pool.lookup("com.stupidbeauty.exist.ExistMessage.MessageType").enummodule
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,19 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: HearchIndexEntry.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_message "com.stupidbeauty.hearch.HearchIndexEntry" do
8
+ optional :keyword, :string, 1
9
+ repeated :articleId, :int32, 2
10
+ end
11
+ end
12
+
13
+ module Com
14
+ module Stupidbeauty
15
+ module Hearch
16
+ HearchIndexEntry = Google::Protobuf::DescriptorPool.generated_pool.lookup("com.stupidbeauty.hearch.HearchIndexEntry").msgclass
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: HearchIndex.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ require 'HearchIndexEntry_pb'
7
+ Google::Protobuf::DescriptorPool.generated_pool.build do
8
+ add_message "com.stupidbeauty.hearch.HearchIndex" do
9
+ repeated :entry, :message, 1, "com.stupidbeauty.hearch.HearchIndexEntry"
10
+ end
11
+ end
12
+
13
+ module Com
14
+ module Stupidbeauty
15
+ module Hearch
16
+ HearchIndex = Google::Protobuf::DescriptorPool.generated_pool.lookup("com.stupidbeauty.hearch.HearchIndex").msgclass
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'eventmachine'
4
+ require 'ipaddr'
5
+
6
+ class MulticastHandler < EventMachine::Connection
7
+ def castData(packageString)
8
+ multicastHost = '239.173.40.5' #组播组主机地址。
9
+ multicastPort = 11500 #组播组端口。
10
+
11
+ # print("castData\n") #Debug.
12
+ # send_data(packageString)
13
+ send_datagram(packageString, multicastHost, multicastPort) #发送组播数据包。
14
+ end
15
+
16
+ def receive_data(data)
17
+ # puts data
18
+ end
19
+
20
+ def post_init
21
+ # print("post_init\n") #Debug.
22
+ port, host = Socket::unpack_sockaddr_in( get_sockname() )
23
+ ip = IPAddr.new( host ).hton + IPAddr.new("0.0.0.0").hton
24
+ set_sock_opt( Socket::IPPROTO_IP, Socket::IP_ADD_MEMBERSHIP, ip )
25
+ end
26
+ end
27
+
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Hearch
3
+ version: !ruby/object:Gem::Version
4
+ version: 2018.8.28
5
+ platform: ruby
6
+ authors:
7
+ - Hxcan Cai
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-08-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: google-protobuf
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 3.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: eventmachine
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.0'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.0'
47
+ description: Hearch ruby. Index and search.
48
+ email: caihuosheng@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/Hearch.rb
54
+ - lib/Hearch/ExistMessage_pb.rb
55
+ - lib/Hearch/HearchIndexEntry_pb.rb
56
+ - lib/Hearch/HearchIndex_pb.rb
57
+ - lib/Hearch/MulticastHandler.rb
58
+ homepage: http://rubygems.org/gems/Hearch
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.5.2.3
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Hearch ruby.
82
+ test_files: []