Exemplo n.º 1
0
// Wraps your custom service in Skynet
func CreateService(sd ServiceDelegate, si *skynet.ServiceInfo) (s *Service) {
	s = &Service{
		Delegate:       sd,
		ServiceInfo:    si,
		methods:        make(map[string]reflect.Value),
		connectionChan: make(chan *net.TCPConn),
		registeredChan: make(chan bool),
		shutdownChan:   make(chan bool),
		ClientInfo:     make(map[string]ClientInfo),
		shuttingDown:   false,
	}

	// Override LogLevel for Service
	if l, err := config.String(s.Name, s.Version, "log.level"); err != nil {
		log.SetLogLevel(log.LevelFromString(l))
	}

	// the main rpc server
	s.RPCServ = rpc.NewServer()
	rpcForwarder := NewServiceRPC(s)
	s.RPCServ.RegisterName(si.Name, rpcForwarder)

	// Daemon doesn't accept commands over pipe
	if si.Name != "SkynetDaemon" {
		// Listen for admin requests
		go s.serveAdminRequests()
	}

	return
}
Exemplo n.º 2
0
func getIdleTimeout(s skynet.ServiceInfo) time.Duration {
	if d, err := config.String(s.Name, s.Version, "client.timeout.idle"); err == nil {
		if timeout, err := time.ParseDuration(d); err != nil {
			return timeout
		}

		log.Println(log.ERROR, "Failed to parse client.timeout.idle", err)
	}

	return config.DefaultIdleTimeout
}
Exemplo n.º 3
0
func getGiveupTimeout(service, version string) time.Duration {
	if d, err := config.String(service, version, "client.timeout.total"); err == nil {
		if timeout, err := time.ParseDuration(d); err == nil {
			log.Println(log.TRACE, fmt.Sprintf("Using custom giveup duration %q for %q %q", timeout.String(), service, version))
			return timeout
		}

		log.Println(log.ERROR, "Failed to parse client.timeout.total", err)
	}

	return config.DefaultRetryDuration
}
Exemplo n.º 4
0
func NewServiceInfo(name, version string) (si *ServiceInfo) {
	// TODO: we need to grab Host/Region/ServiceAddr from config
	si = &ServiceInfo{
		Name:    name,
		Version: version,
		UUID:    config.UUID(),
	}

	var host string
	var minPort, maxPort int

	if r, err := config.String(name, version, "region"); err == nil {
		si.Region = r
	} else {
		si.Region = config.DefaultRegion
	}

	if h, err := config.String(name, version, "host"); err == nil {
		host = h
	} else {
		host = config.DefaultHost
	}

	if p, err := config.Int(name, version, "service.port.min"); err == nil {
		minPort = p
	} else {
		minPort = config.DefaultMinPort
	}

	if p, err := config.Int(name, version, "service.port.max"); err == nil {
		maxPort = p
	} else {
		maxPort = config.DefaultMaxPort
	}

	log.Println(log.TRACE, host, minPort, maxPort)
	si.ServiceAddr = BindAddr{IPAddress: host, Port: minPort, MaxPort: maxPort}

	return si
}