Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fcploadplugin #14

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions fcp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#from invertkey import main as invertkey
#from redirect import main as redirect
#from names import main as names
import upload, put, get, genkey, invertkey, redirect, names
import upload, put, get, genkey, invertkey, redirect, names, loadplugin
import fproxyproxy
#import fproxyaddref
import pseudopythonparser
Expand All @@ -28,7 +28,7 @@
'ConnectionRefused', 'FCPException', 'FCPPutFailed',
'FCPProtocolError',
'get', 'put', 'genkey', 'invertkey', 'redirect', 'names',
'fproxyproxy', "fproxyaddref",
'fproxyproxy', "fproxyaddref", "loadplugin",
]

if not isDoze:
Expand Down
100 changes: 100 additions & 0 deletions fcp/loadplugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"""
load a freenet plugin

This is the guts of the command-line front-end app fcploadplugin
"""

#@+others
#@+node:imports
import argparse
import sys
import traceback
import os.path
from urlparse import urlparse

from . import node
from .arguments import add_default_arguments

#@-node:imports
#@+node:globals

#@-node:globals
#@+node:usage
def create_parser():
'''
Creates an argparse parser.
'''
parser = argparse.ArgumentParser(
prog='fcploadplugin',
description='''
A simple command-line freenet load plugin command.

Loads a plugin to the running node.
''',
)
add_default_arguments(parser)

parser.add_argument(
'plugin_uri',
help='''
A URI that points to the plugin location.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to clarify that this can either be a path in the filesystem (looks assumed to be the same as the node's) or a Freenet key.

EDIT: it looks like this would work for things like "official:WebOfTrust" too?

''',
)

return parser

#@-node:help
#@+node:main
def main(argv=sys.argv[1:]):
"""
Front end for fcploadplugin utility
"""

# default job options
verbosity = node.ERROR
verbose = False

parser = create_parser()
args = parser.parse_args(argv)
uri = args.plugin_uri

keytypes = ["USK", "KSK", "SSK", "CHK"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't a list of these already?


if os.path.isfile(uri) \
or os.path.islink(uri) and os.path.isfile(os.path.realpath(uri)):
if uri.endswith(".jar"):
plugin_uri = uri
elif urlparse(uri).scheme != "":
plugin_uri = uri
else:
if not uri.startswith("freenet:"):
uri = "freenet:" + uri
if uri[len("freenet:"):len("freenet:")+3] in keytypes:
plugin_uri = uri

try:
plugin_uri
except NameError:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a very strange way to check for validity. Do these bindings really not have some kind of key class that will parse them?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. These utilities could use some cleanup then - I don't see a good reason to parse like that. In addition, such common things should be implemented in the library instead of the included utilities to avoid such a large pressure toward duplicating code. I'm surprised there isn't a FreenetKey class in the library already.

Is there a reason to parse this? My understanding is that the leading "freenet:" is unnecessary. There are no decisions made from parsing at this level other than to error out when it's invalid. Would it work to send it to the node without checking it and let the node return any errors?

sys.stderr.write("The given plugin uri is not valid.\n")
sys.exit(1)

# try to create the node
try:
fcp_node = node.FCPNode(host=args.fcphost, port=args.fcpport, verbosity=verbosity,
logfile=sys.stderr)
except:
if verbose:
traceback.print_exc(file=sys.stderr)
sys.stderr.write("Failed to connect to FCP service at %s:%d\n" % (args.fcphost, args.fcpport))
sys.exit(2)

# send the LoadPlugin request
fcp_node.fcpLoadPlugin(plugin_uri)

fcp_node.shutdown()

# successful
print "Plugin successfully loaded."

# all done
sys.exit(0)
30 changes: 30 additions & 0 deletions fcp/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,27 @@ def fcpPluginMessage(self, **kw):
params.update({'Param.%s' % str(key) : val})

return self._submitCmd(id, "FCPPluginMessage", **params)

def fcpLoadPlugin(self, plugin_uri, **kw):
"""
Sends an LoadPlugin message
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"LoadPlugin" doesn't start with a vowel sound so "an" should be "a" here.


Keywords:
- PluginURL - An URI that point to the plugin location
- URLType - Type of plugin source. (currently autodection does not work if
the local file does not exist or type is 'url'), default Attempts autodetect
- Store - If true, the plugin url is written to config, default false
- OfficialSource - Means of obtaining an official plugin: freenet or HTTPS
"""

id = kw.pop("id", None)
if not id:
id = self._getUniqueId()

params = dict(Identifier = id,
PluginURL = plugin_uri)

return self._submitCmd(id, "LoadPlugin", **params)

#@+node:get
def get(self, uri, **kw):
Expand Down Expand Up @@ -2409,6 +2430,15 @@ def _on_rxMsg(self, msg):
job.callback('successful', job.msgs)
job._putResult(job.msgs)
return

# -----------------------------
# handle LoadPlugin replies

if hdr == 'PluginInfo':
job._appendMsg(msg)
job.callback('successful', job.msgs)
job._putResult(job.msgs)
return

# -----------------------------
# handle peer management messages
Expand Down
3 changes: 3 additions & 0 deletions fcploadplugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env python2
import fcp
fcp.loadplugin.main()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

scripts = ["freesitemgr", "pyNodeConfig",
"fcpget", "fcpput", "fcpupload", "fcpgenkey", "fcpinvertkey", "fcpredirect", "fcpnames",
"fproxyproxy"# , "freedisk" # <- not yet reviewed
"fproxyproxy", "loadplugin"# , "freedisk" # <- not yet reviewed
]
if doze:
for i in range(len(scripts)):
Expand Down