2019-06-12 06:44:15 +00:00
|
|
|
'''
|
|
|
|
Onionr - Private P2P Communication
|
|
|
|
|
|
|
|
Creates an onionr direct connection service by scanning all connection blocks
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
'''
|
2019-03-24 02:56:46 +00:00
|
|
|
import communicator, onionrblockapi
|
2019-06-23 17:41:07 +00:00
|
|
|
from onionrutils import stringvalidators
|
|
|
|
|
2019-03-24 02:56:46 +00:00
|
|
|
def service_creator(daemon):
|
|
|
|
assert isinstance(daemon, communicator.OnionrCommunicatorDaemon)
|
|
|
|
core = daemon._core
|
|
|
|
utils = core._utils
|
|
|
|
|
|
|
|
# Find socket connection blocks
|
2019-06-12 06:44:15 +00:00
|
|
|
# TODO cache blocks and only look at recently received ones
|
2019-03-24 02:56:46 +00:00
|
|
|
con_blocks = core.getBlocksByType('con')
|
|
|
|
for b in con_blocks:
|
|
|
|
if not b in daemon.active_services:
|
|
|
|
bl = onionrblockapi.Block(b, core=core, decrypt=True)
|
|
|
|
bs = utils.bytesToStr(bl.bcontent) + '.onion'
|
2019-06-25 08:21:36 +00:00
|
|
|
if stringvalidators.validate_pub_key(bl.signer) and stringvalidators.validate_transport(bs):
|
2019-04-02 16:50:09 +00:00
|
|
|
signer = utils.bytesToStr(bl.signer)
|
2019-03-24 02:56:46 +00:00
|
|
|
daemon.active_services.append(b)
|
2019-04-02 16:50:09 +00:00
|
|
|
daemon.active_services.append(signer)
|
|
|
|
daemon.services.create_server(signer, bs)
|
2019-03-24 02:56:46 +00:00
|
|
|
|
|
|
|
daemon.decrementThreadCount('service_creator')
|