1// Copyright 2018 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5package osp
6
7// TODO(pthatcher):
8// - Write messages as well
9
10import (
11	"context"
12	"crypto/tls"
13	"io"
14)
15
16func ReadMessagesAsServer(ctx context.Context, instanceName string, port int, cert tls.Certificate, messages chan<- interface{}) error {
17	// TODO(pthatcher): log error if it fails
18	go RunMdnsServer(ctx, instanceName, port)
19	streams := make(chan io.ReadWriteCloser)
20	go RunQuicServer(ctx, port, cert, streams)
21
22	for stream := range streams {
23		msg, err := ReadMessage(stream)
24		if err != nil {
25			return err
26		}
27		messages <- msg
28	}
29	return nil
30}
31