github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/services/noop/service.go (about) 1 /* 2 * Copyright (C) 2018 The "MysteriumNetwork/node" Authors. 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 package noop 19 20 import ( 21 "encoding/json" 22 "net" 23 "sync" 24 25 "github.com/mysteriumnetwork/node/core/service" 26 "github.com/pkg/errors" 27 "github.com/rs/zerolog/log" 28 ) 29 30 // ErrAlreadyStarted is the error we return when the start is called multiple times 31 var ErrAlreadyStarted = errors.New("service already started") 32 33 // NewManager creates new instance of Noop service 34 func NewManager() *Manager { 35 return &Manager{} 36 } 37 38 // Manager represents entrypoint for Noop service 39 type Manager struct { 40 process sync.WaitGroup 41 } 42 43 // ProvideConfig provides the session configuration 44 func (manager *Manager) ProvideConfig(_ string, _ json.RawMessage, _ *net.UDPConn) (*service.ConfigParams, error) { 45 return &service.ConfigParams{}, nil 46 } 47 48 // Serve starts service - does block 49 func (manager *Manager) Serve(instance *service.Instance) error { 50 manager.process.Add(1) 51 log.Info().Msg("Noop service started successfully") 52 manager.process.Wait() 53 return nil 54 } 55 56 // Stop stops service 57 func (manager *Manager) Stop() error { 58 manager.process.Done() 59 log.Info().Msg("Noop service stopped") 60 return nil 61 }