mirror of
https://github.com/LorenEteval/Furious.git
synced 2026-10-02 11:57:55 +03:00
131 lines
4.0 KiB
Python
131 lines
4.0 KiB
Python
# Copyright (C) 2024–present Loren Eteval & contributors <loren.eteval@proton.me>
|
||
#
|
||
# This file is part of Furious.
|
||
#
|
||
# 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/>.
|
||
|
||
"""Define the public contract implemented by Furious core plugins."""
|
||
|
||
from __future__ import annotations
|
||
|
||
from dataclasses import dataclass
|
||
|
||
__all__ = [
|
||
'PLUGIN_API_VERSION',
|
||
'PluginProtocol',
|
||
'PluginRouting',
|
||
'FuriousPlugin',
|
||
]
|
||
|
||
PLUGIN_API_VERSION = 1
|
||
|
||
|
||
@dataclass(frozen=True)
|
||
class PluginProtocol:
|
||
"""Describe one server protocol contributed by a plugin."""
|
||
|
||
id: str
|
||
displayName: str
|
||
addActionText: str
|
||
menuOrder: int = 0
|
||
separatorBefore: bool = False
|
||
|
||
|
||
@dataclass(frozen=True)
|
||
class PluginRouting:
|
||
"""Describe one routing mode supported by a core plugin."""
|
||
|
||
id: str
|
||
displayName: str
|
||
separatorBefore: bool = False
|
||
translatable: bool = False
|
||
|
||
|
||
class FuriousPlugin:
|
||
"""Provide configuration, UI, and process hooks for one proxy core family."""
|
||
|
||
apiVersion = PLUGIN_API_VERSION
|
||
pluginId = ''
|
||
displayName = ''
|
||
protocols = tuple()
|
||
configurationTypes = tuple()
|
||
coreTypes = tuple()
|
||
|
||
def configFromString(self, config: str, **kwargs):
|
||
"""Construct a supported configuration from text or return ``None``."""
|
||
return None
|
||
|
||
def configFromDict(self, config: dict, **kwargs):
|
||
"""Construct a supported configuration mapping or return ``None``."""
|
||
return None
|
||
|
||
def blankConfig(self, protocol, **kwargs):
|
||
"""Construct a blank configuration for a contributed protocol."""
|
||
return None
|
||
|
||
def createEditorForProtocol(self, protocol, parent=None, **kwargs):
|
||
"""Create the configuration editor for a contributed protocol."""
|
||
return None
|
||
|
||
def createEditorForConfig(self, config, parent=None, **kwargs):
|
||
"""Create the configuration editor for a plugin configuration."""
|
||
return self.createEditorForProtocol(config.itemProtocol, parent, **kwargs)
|
||
|
||
def createManagementActions(self, parent=None, **kwargs):
|
||
"""Return optional actions for this plugin's management submenu."""
|
||
return tuple()
|
||
|
||
def prepareTUN(self, config) -> bool:
|
||
"""Prepare plugin-native TUN and return whether the plugin handles it."""
|
||
return False
|
||
|
||
def routingOptions(self, config=None):
|
||
"""Return routing modes supported for a plugin configuration."""
|
||
return tuple()
|
||
|
||
def configureEnvironment(self):
|
||
"""Set optional process environment required by the plugin core."""
|
||
|
||
def startCore(
|
||
self,
|
||
config,
|
||
routing,
|
||
exitCallback=None,
|
||
msgCallback=None,
|
||
proxyModeOnly=False,
|
||
log=True,
|
||
**kwargs,
|
||
):
|
||
"""Start the plugin core and return ``(process, success)``."""
|
||
return None, False
|
||
|
||
def prepareDownloadTest(self, config, port: int):
|
||
"""Return a proxy-only configuration for a download-speed test."""
|
||
return None
|
||
|
||
def coreVersions(self):
|
||
"""Return core version strings that should be treated as versions in logs."""
|
||
return tuple()
|
||
|
||
def logTimestampPatterns(self):
|
||
"""Return regular expressions for timestamps emitted by the plugin core."""
|
||
return tuple()
|
||
|
||
def coreExitMessage(self, core, exitcode: int):
|
||
"""Return a user-facing message key for a plugin-specific exit code."""
|
||
return None
|
||
|
||
def afterConnected(self, httpProxy=None):
|
||
"""Perform optional plugin maintenance after a connection succeeds."""
|