MCPcopy Index your code
hub / github.com/coder/coder / validateHeader

Function validateHeader

vpn/speaker.go:334–355  ·  view source on GitHub ↗
(header string, expectedRole SpeakerRole, supportedVersions RPCVersionList)

Source from the content-addressed store, hash-verified

332}
333
334func validateHeader(header string, expectedRole SpeakerRole, supportedVersions RPCVersionList) (RPCVersion, error) {
335 parts := strings.Split(header, " ")
336 if len(parts) != 3 {
337 return RPCVersion{}, xerrors.New("wrong number of parts")
338 }
339 if parts[0] != headerPreamble {
340 return RPCVersion{}, xerrors.New("invalid preamble")
341 }
342 if parts[1] != string(expectedRole) {
343 return RPCVersion{}, xerrors.New("unexpected role")
344 }
345 otherVersions, err := ParseRPCVersionList(parts[2])
346 if err != nil {
347 return RPCVersion{}, xerrors.Errorf("parse version list %q: %w", parts[2], err)
348 }
349 compatibleVersion, ok := supportedVersions.IsCompatibleWith(otherVersions)
350 if !ok {
351 return RPCVersion{},
352 xerrors.Errorf("current supported versions %q is not compatible with peer versions %q", supportedVersions.String(), otherVersions.String())
353 }
354 return compatibleVersion, nil
355}
356
357type request[S rpcMessage, R rpcMessage] struct {
358 ctx context.Context

Callers 1

handshakeFunction · 0.85

Calls 5

ParseRPCVersionListFunction · 0.85
NewMethod · 0.65
ErrorfMethod · 0.45
IsCompatibleWithMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected