Improve server selection somewhat
This commit is contained in:
parent
f9547a53d2
commit
ddb11b2bc2
|
@ -130,7 +130,10 @@ func (r *Inputer) processRoomEvent(
|
||||||
return fmt.Errorf("r.Queryer.QueryMissingAuthPrevEvents: %w", err)
|
return fmt.Errorf("r.Queryer.QueryMissingAuthPrevEvents: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(missingRes.MissingAuthEventIDs) > 0 || len(missingRes.MissingPrevEventIDs) > 0 {
|
missingAuth := len(missingRes.MissingAuthEventIDs) > 0
|
||||||
|
missingPrev := !input.HasState && len(missingRes.MissingPrevEventIDs) > 0
|
||||||
|
|
||||||
|
if missingAuth || missingPrev {
|
||||||
serverReq := &fedapi.QueryJoinedHostServerNamesInRoomRequest{
|
serverReq := &fedapi.QueryJoinedHostServerNamesInRoomRequest{
|
||||||
RoomID: event.RoomID(),
|
RoomID: event.RoomID(),
|
||||||
ExcludeSelf: true,
|
ExcludeSelf: true,
|
||||||
|
@ -138,9 +141,25 @@ func (r *Inputer) processRoomEvent(
|
||||||
if err = r.FSAPI.QueryJoinedHostServerNamesInRoom(ctx, serverReq, serverRes); err != nil {
|
if err = r.FSAPI.QueryJoinedHostServerNamesInRoom(ctx, serverReq, serverRes); err != nil {
|
||||||
return fmt.Errorf("r.FSAPI.QueryJoinedHostServerNamesInRoom: %w", err)
|
return fmt.Errorf("r.FSAPI.QueryJoinedHostServerNamesInRoom: %w", err)
|
||||||
}
|
}
|
||||||
|
// Sort all of the servers into a map so that we can randomise
|
||||||
|
// their order. Then make sure that the input origin and the
|
||||||
|
// event origin are first on the list.
|
||||||
|
servers := map[gomatrixserverlib.ServerName]struct{}{}
|
||||||
|
for _, server := range serverRes.ServerNames {
|
||||||
|
servers[server] = struct{}{}
|
||||||
}
|
}
|
||||||
|
serverRes.ServerNames = serverRes.ServerNames[:0]
|
||||||
if input.Origin != "" {
|
if input.Origin != "" {
|
||||||
serverRes.ServerNames = append(serverRes.ServerNames, input.Origin)
|
serverRes.ServerNames = append(serverRes.ServerNames, input.Origin)
|
||||||
|
delete(servers, input.Origin)
|
||||||
|
}
|
||||||
|
if origin := event.Origin(); origin != input.Origin {
|
||||||
|
serverRes.ServerNames = append(serverRes.ServerNames, origin)
|
||||||
|
delete(servers, origin)
|
||||||
|
}
|
||||||
|
for server := range servers {
|
||||||
|
serverRes.ServerNames = append(serverRes.ServerNames, server)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// First of all, check that the auth events of the event are known.
|
// First of all, check that the auth events of the event are known.
|
||||||
|
@ -190,7 +209,6 @@ func (r *Inputer) processRoomEvent(
|
||||||
// typical federated room join) then we won't bother trying to fetch prev events
|
// typical federated room join) then we won't bother trying to fetch prev events
|
||||||
// because we may not be allowed to see them and we have no choice but to trust
|
// because we may not be allowed to see them and we have no choice but to trust
|
||||||
// the state event IDs provided to us in the join instead.
|
// the state event IDs provided to us in the join instead.
|
||||||
missingPrev := !input.HasState && len(missingRes.MissingPrevEventIDs) > 0
|
|
||||||
if missingPrev && input.Kind == api.KindNew {
|
if missingPrev && input.Kind == api.KindNew {
|
||||||
// Don't do this for KindOld events, otherwise old events that we fetch
|
// Don't do this for KindOld events, otherwise old events that we fetch
|
||||||
// to satisfy missing prev events/state will end up recursively calling
|
// to satisfy missing prev events/state will end up recursively calling
|
||||||
|
@ -204,13 +222,10 @@ func (r *Inputer) processRoomEvent(
|
||||||
federation: r.FSAPI,
|
federation: r.FSAPI,
|
||||||
keys: r.KeyRing,
|
keys: r.KeyRing,
|
||||||
roomsMu: internal.NewMutexByRoom(),
|
roomsMu: internal.NewMutexByRoom(),
|
||||||
servers: map[gomatrixserverlib.ServerName]struct{}{},
|
servers: serverRes.ServerNames,
|
||||||
hadEvents: map[string]bool{},
|
hadEvents: map[string]bool{},
|
||||||
haveEvents: map[string]*gomatrixserverlib.HeaderedEvent{},
|
haveEvents: map[string]*gomatrixserverlib.HeaderedEvent{},
|
||||||
}
|
}
|
||||||
for _, serverName := range serverRes.ServerNames {
|
|
||||||
missingState.servers[serverName] = struct{}{}
|
|
||||||
}
|
|
||||||
if err = missingState.processEventWithMissingState(ctx, event, headered.RoomVersion); err != nil {
|
if err = missingState.processEventWithMissingState(ctx, event, headered.RoomVersion); err != nil {
|
||||||
isRejected = true
|
isRejected = true
|
||||||
rejectionErr = fmt.Errorf("missingState.processEventWithMissingState: %w", err)
|
rejectionErr = fmt.Errorf("missingState.processEventWithMissingState: %w", err)
|
||||||
|
|
|
@ -25,7 +25,7 @@ type missingStateReq struct {
|
||||||
keys gomatrixserverlib.JSONVerifier
|
keys gomatrixserverlib.JSONVerifier
|
||||||
federation fedapi.FederationInternalAPI
|
federation fedapi.FederationInternalAPI
|
||||||
roomsMu *internal.MutexByRoom
|
roomsMu *internal.MutexByRoom
|
||||||
servers map[gomatrixserverlib.ServerName]struct{}
|
servers []gomatrixserverlib.ServerName
|
||||||
hadEvents map[string]bool
|
hadEvents map[string]bool
|
||||||
hadEventsMutex sync.Mutex
|
hadEventsMutex sync.Mutex
|
||||||
haveEvents map[string]*gomatrixserverlib.HeaderedEvent
|
haveEvents map[string]*gomatrixserverlib.HeaderedEvent
|
||||||
|
@ -417,7 +417,7 @@ func (t *missingStateReq) getMissingEvents(ctx context.Context, e *gomatrixserve
|
||||||
}
|
}
|
||||||
|
|
||||||
var missingResp *gomatrixserverlib.RespMissingEvents
|
var missingResp *gomatrixserverlib.RespMissingEvents
|
||||||
for server := range t.servers {
|
for _, server := range t.servers {
|
||||||
var m gomatrixserverlib.RespMissingEvents
|
var m gomatrixserverlib.RespMissingEvents
|
||||||
if m, err = t.federation.LookupMissingEvents(ctx, server, e.RoomID(), gomatrixserverlib.MissingEvents{
|
if m, err = t.federation.LookupMissingEvents(ctx, server, e.RoomID(), gomatrixserverlib.MissingEvents{
|
||||||
Limit: 20,
|
Limit: 20,
|
||||||
|
@ -700,7 +700,7 @@ func (t *missingStateReq) lookupEvent(ctx context.Context, roomVersion gomatrixs
|
||||||
}
|
}
|
||||||
var event *gomatrixserverlib.Event
|
var event *gomatrixserverlib.Event
|
||||||
found := false
|
found := false
|
||||||
for serverName := range t.servers {
|
for _, serverName := range t.servers {
|
||||||
reqctx, cancel := context.WithTimeout(ctx, time.Second*30)
|
reqctx, cancel := context.WithTimeout(ctx, time.Second*30)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
txn, err := t.federation.GetEvent(reqctx, serverName, missingEventID)
|
txn, err := t.federation.GetEvent(reqctx, serverName, missingEventID)
|
||||||
|
|
Loading…
Reference in a new issue