2019-12-23 07:51:24 +00:00
|
|
|
"""
|
|
|
|
Onionr - Private P2P Communication.
|
2019-06-13 02:35:30 +00:00
|
|
|
|
2019-12-23 07:51:24 +00:00
|
|
|
Use a communicator instance to announce
|
|
|
|
our transport address to connected nodes
|
|
|
|
"""
|
|
|
|
import base64
|
|
|
|
import onionrproofs
|
|
|
|
import logger
|
|
|
|
from etc import onionrvalues
|
|
|
|
from onionrutils import basicrequests, bytesconverter
|
|
|
|
from utils import gettransports
|
|
|
|
from netcontroller import NetController
|
|
|
|
from communicator import onlinepeers
|
|
|
|
from coredb import keydb
|
|
|
|
import onionrexceptions
|
|
|
|
"""
|
2019-06-13 02:35:30 +00:00
|
|
|
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-12-23 07:51:24 +00:00
|
|
|
"""
|
|
|
|
|
2019-12-20 07:24:38 +00:00
|
|
|
|
2019-06-13 02:35:30 +00:00
|
|
|
def announce_node(daemon):
|
2019-12-23 07:51:24 +00:00
|
|
|
"""Announce our node to our peers."""
|
2019-08-09 20:41:27 +00:00
|
|
|
ret_data = False
|
|
|
|
announce_fail = False
|
2019-12-23 07:51:24 +00:00
|
|
|
|
2019-06-13 02:35:30 +00:00
|
|
|
# Do not let announceCache get too large
|
|
|
|
if len(daemon.announceCache) >= 10000:
|
|
|
|
daemon.announceCache.popitem()
|
|
|
|
|
2019-07-18 17:40:48 +00:00
|
|
|
if daemon.config.get('general.security_level', 0) == 0:
|
2019-06-13 02:35:30 +00:00
|
|
|
# Announce to random online peers
|
|
|
|
for i in daemon.onlinePeers:
|
2019-12-23 07:51:24 +00:00
|
|
|
if i not in daemon.announceCache and\
|
|
|
|
i not in daemon.announceProgress:
|
2019-06-13 02:35:30 +00:00
|
|
|
peer = i
|
|
|
|
break
|
|
|
|
else:
|
2019-12-20 07:24:38 +00:00
|
|
|
try:
|
|
|
|
peer = onlinepeers.pick_online_peer(daemon)
|
|
|
|
except onionrexceptions.OnlinePeerNeeded:
|
|
|
|
peer = ""
|
2019-06-13 02:35:30 +00:00
|
|
|
|
2020-01-20 03:02:04 +00:00
|
|
|
try:
|
|
|
|
ourID = gettransports.get()[0]
|
|
|
|
if not peer:
|
|
|
|
raise onionrexceptions.OnlinePeerNeeded
|
|
|
|
except (IndexError, onionrexceptions.OnlinePeerNeeded):
|
|
|
|
pass
|
|
|
|
else:
|
2019-06-13 02:35:30 +00:00
|
|
|
url = 'http://' + peer + '/announce'
|
|
|
|
data = {'node': ourID}
|
|
|
|
|
2020-01-20 03:02:04 +00:00
|
|
|
logger.info('Announcing node to ' + url)
|
|
|
|
if basicrequests.do_post_request(
|
|
|
|
url,
|
|
|
|
data,
|
|
|
|
port=daemon.shared_state.get(NetController).socksPort)\
|
|
|
|
== 'Success':
|
|
|
|
logger.info('Successfully introduced node to ' + peer,
|
|
|
|
terminal=True)
|
|
|
|
ret_data = True
|
|
|
|
keydb.transportinfo.set_address_info(peer, 'introduced', 1)
|
2019-06-13 02:35:30 +00:00
|
|
|
|
2019-06-13 06:58:17 +00:00
|
|
|
daemon.decrementThreadCount('announce_node')
|
2019-12-23 07:51:24 +00:00
|
|
|
return ret_data
|