This commit is contained in:
@@ -11,7 +11,6 @@ import (
|
||||
"time"
|
||||
|
||||
"git.eeqj.de/sneak/feta/jsonapis"
|
||||
"git.eeqj.de/sneak/feta/storage"
|
||||
"git.eeqj.de/sneak/feta/toot"
|
||||
"github.com/google/uuid"
|
||||
"github.com/looplab/fsm"
|
||||
@@ -26,14 +25,6 @@ const instanceHTTPTimeout = time.Second * 120
|
||||
const instanceSpiderInterval = time.Second * 120
|
||||
const instanceErrorInterval = time.Second * 60 * 30
|
||||
|
||||
type instanceImplementation int
|
||||
|
||||
const (
|
||||
implUnknown instanceImplementation = iota
|
||||
implMastodon
|
||||
implPleroma
|
||||
)
|
||||
|
||||
// Instance stores all the information we know about an instance
|
||||
type Instance struct {
|
||||
Disabled bool
|
||||
@@ -42,17 +33,17 @@ type Instance struct {
|
||||
Fetching bool
|
||||
HighestID uint
|
||||
Hostname string
|
||||
UUID uuid.UUID
|
||||
Identified bool
|
||||
Implementation instanceImplementation
|
||||
Implementation string
|
||||
InitialFSMState string
|
||||
NextFetch time.Time
|
||||
NodeInfoURL string
|
||||
ServerImplementationString string
|
||||
ServerVersionString string
|
||||
SuccessCount uint
|
||||
UUID uuid.UUID
|
||||
fetchingLock sync.Mutex
|
||||
fsmLock sync.Mutex
|
||||
storageBackend *storage.TootStorageBackend
|
||||
structLock sync.Mutex
|
||||
tootDestination chan *toot.Toot
|
||||
}
|
||||
@@ -63,9 +54,14 @@ func New(options ...func(i *Instance)) *Instance {
|
||||
i := new(Instance)
|
||||
i.UUID = uuid.New()
|
||||
i.setNextFetchAfter(1 * time.Second)
|
||||
i.InitialFSMState = "STATUS_UNKNOWN"
|
||||
|
||||
for _, opt := range options {
|
||||
opt(i)
|
||||
}
|
||||
|
||||
i.FSM = fsm.NewFSM(
|
||||
"STATUS_UNKNOWN",
|
||||
i.InitialFSMState,
|
||||
fsm.Events{
|
||||
{Name: "BEGIN_NODEINFO_URL_FETCH", Src: []string{"STATUS_UNKNOWN"}, Dst: "FETCHING_NODEINFO_URL"},
|
||||
{Name: "GOT_NODEINFO_URL", Src: []string{"FETCHING_NODEINFO_URL"}, Dst: "PRE_NODEINFO_FETCH"},
|
||||
@@ -82,10 +78,6 @@ func New(options ...func(i *Instance)) *Instance {
|
||||
"enter_state": func(e *fsm.Event) { i.fsmEnterState(e) },
|
||||
},
|
||||
)
|
||||
|
||||
for _, opt := range options {
|
||||
opt(i)
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
@@ -195,7 +187,7 @@ func (i *Instance) Tick() {
|
||||
func (i *Instance) nodeIdentified() bool {
|
||||
i.Lock()
|
||||
defer i.Unlock()
|
||||
if i.Implementation > implUnknown {
|
||||
if i.Implementation != "" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
@@ -379,7 +371,7 @@ func (i *Instance) fetchNodeInfo() error {
|
||||
Str("software", ni.Software.Name).
|
||||
Msg("detected server software")
|
||||
i.Identified = true
|
||||
i.Implementation = implPleroma
|
||||
i.Implementation = "pleroma"
|
||||
i.Unlock()
|
||||
i.registerSuccess()
|
||||
i.Event("GOT_NODEINFO")
|
||||
@@ -390,7 +382,7 @@ func (i *Instance) fetchNodeInfo() error {
|
||||
Str("software", ni.Software.Name).
|
||||
Msg("detected server software")
|
||||
i.Identified = true
|
||||
i.Implementation = implMastodon
|
||||
i.Implementation = "mastodon"
|
||||
i.Unlock()
|
||||
i.registerSuccess()
|
||||
i.Event("GOT_NODEINFO")
|
||||
|
||||
Reference in New Issue
Block a user