Onionr/onionr/static-data/default-plugins/metadataprocessor/main.py

60 lines
1.8 KiB
Python
Raw Normal View History

2018-11-11 02:10:58 +00:00
'''
2019-06-20 07:59:32 +00:00
Onionr - Private P2P Communication
2018-11-11 02:10:58 +00:00
This processes metadata for Onionr 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/>.
'''
# useful libraries
import logger, config
import os, sys, json, time, random, shutil, base64, getpass, datetime, re
import onionrusers, onionrexceptions
from onionrutils import stringvalidators
2018-11-11 02:10:58 +00:00
plugin_name = 'metadataprocessor'
# event listeners
def _processForwardKey(api, myBlock):
'''
Get the forward secrecy key specified by the user for us to use
'''
2019-07-20 06:02:30 +00:00
peer = onionrusers.OnionrUser(myBlock.signer)
2018-11-11 02:10:58 +00:00
key = myBlock.getMetadata('newFSKey')
# We don't need to validate here probably, but it helps
if stringvalidators.validate_pub_key(key):
2018-11-11 02:10:58 +00:00
peer.addForwardKey(key)
else:
2019-04-21 00:31:14 +00:00
raise onionrexceptions.InvalidPubkey("%s is not a valid pubkey key" % (key,))
2018-11-11 02:10:58 +00:00
def on_processblocks(api, data=None):
2018-11-11 02:10:58 +00:00
# Generally fired by utils.
myBlock = api.data['block']
blockType = api.data['type']
# Process specific block types
# forwardKey blocks, add a new forward secrecy key for a peer
if blockType == 'forwardKey':
2018-11-11 02:10:58 +00:00
if api.data['validSig'] == True:
_processForwardKey(api, myBlock)
2018-11-11 02:10:58 +00:00
def on_init(api, data = None):
pluginapi = api
return