2019-08-02 01:09:01 +00:00
|
|
|
package plugins
|
|
|
|
|
|
|
|
import (
|
|
|
|
"cwtch.im/cwtch/event"
|
2021-12-08 01:02:23 +00:00
|
|
|
"fmt"
|
2020-02-10 22:09:24 +00:00
|
|
|
"git.openprivacy.ca/openprivacy/connectivity"
|
2019-08-02 01:09:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// PluginID is used as an ID for signaling plugin activities
|
|
|
|
type PluginID int
|
|
|
|
|
|
|
|
// These are the plugin IDs for the supplied plugins
|
|
|
|
const (
|
2019-09-26 23:43:34 +00:00
|
|
|
CONNECTIONRETRY PluginID = iota
|
2019-10-31 23:05:01 +00:00
|
|
|
NETWORKCHECK
|
2022-09-10 17:15:32 +00:00
|
|
|
ANTISPAM
|
2023-04-03 19:44:28 +00:00
|
|
|
HEARTBEAT
|
2019-08-02 01:09:01 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Plugin is the interface for a plugin
|
|
|
|
type Plugin interface {
|
|
|
|
Start()
|
|
|
|
Shutdown()
|
2022-12-03 00:23:11 +00:00
|
|
|
Id() PluginID
|
2019-08-02 01:09:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get is a plugin factory for the requested plugin
|
2021-12-08 01:02:23 +00:00
|
|
|
func Get(id PluginID, bus event.Manager, acn connectivity.ACN, onion string) (Plugin, error) {
|
2019-08-02 01:09:01 +00:00
|
|
|
switch id {
|
2019-09-26 23:43:34 +00:00
|
|
|
case CONNECTIONRETRY:
|
2021-12-08 01:02:23 +00:00
|
|
|
return NewConnectionRetry(bus, onion), nil
|
2019-10-31 23:05:01 +00:00
|
|
|
case NETWORKCHECK:
|
2022-03-22 19:44:18 +00:00
|
|
|
return NewNetworkCheck(onion, bus, acn), nil
|
2022-09-10 17:15:32 +00:00
|
|
|
case ANTISPAM:
|
|
|
|
return NewAntiSpam(bus), nil
|
2023-04-03 19:44:28 +00:00
|
|
|
case HEARTBEAT:
|
|
|
|
return NewHeartbeat(bus), nil
|
2019-08-02 01:09:01 +00:00
|
|
|
}
|
|
|
|
|
2021-12-08 01:02:23 +00:00
|
|
|
return nil, fmt.Errorf("plugin not defined %v", id)
|
2019-08-02 01:09:01 +00:00
|
|
|
}
|