MCPcopy
hub / github.com/syncthing/syncthing / OnHello

Method OnHello

lib/model/model.go:2264–2285  ·  view source on GitHub ↗

OnHello is called when an device connects to us. This allows us to extract some information from the Hello message and add it to a list of known devices ahead of any checks.

(remoteID protocol.DeviceID, addr net.Addr, hello protocol.Hello)

Source from the content-addressed store, hash-verified

2262// This allows us to extract some information from the Hello message
2263// and add it to a list of known devices ahead of any checks.
2264func (m *model) OnHello(remoteID protocol.DeviceID, addr net.Addr, hello protocol.Hello) error {
2265 if _, ok := m.cfg.Device(remoteID); !ok {
2266 if err := m.observed.AddOrUpdatePendingDevice(remoteID, hello.DeviceName, addr.String()); err != nil {
2267 slog.Warn("Failed to persist pending device entry to database", slogutil.Error(err))
2268 }
2269 m.evLogger.Log(events.PendingDevicesChanged, map[string][]interface{}{
2270 "added": {map[string]string{
2271 "deviceID": remoteID.String(),
2272 "name": hello.DeviceName,
2273 "address": addr.String(),
2274 }},
2275 })
2276 // DEPRECATED: Only for backwards compatibility, should be removed.
2277 m.evLogger.Log(events.DeviceRejected, map[string]string{
2278 "name": hello.DeviceName,
2279 "device": remoteID.String(),
2280 "address": addr.String(),
2281 })
2282 return errDeviceUnknown
2283 }
2284 return nil
2285}
2286
2287// AddConnection adds a new peer connection to the model. An initial index will
2288// be sent to the connected peer, thereafter index updates whenever the local

Callers

nothing calls this directly

Calls 5

ErrorFunction · 0.92
DeviceMethod · 0.65
StringMethod · 0.65
LogMethod · 0.65

Tested by

no test coverage detected