client

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2022 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 17 Imported by: 0

Documentation

Overview

*

  • Tencent is pleased to support the open source community by making polaris-go available. *
  • Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. *
  • Licensed under the BSD 3-Clause License (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • https://opensource.org/licenses/BSD-3-Clause *
  • Unless required by applicable law or agreed to in writing, software distributed
  • under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  • CONDITIONS OF ANY KIND, either express or implied. See the License for the
  • specific language governing permissions and limitations under the License.

*

  • Tencent is pleased to support the open source community by making polaris-go available. *
  • Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. *
  • Licensed under the BSD 3-Clause License (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • https://opensource.org/licenses/BSD-3-Clause *
  • Unless required by applicable law or agreed to in writing, software distributed
  • under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  • CONDITIONS OF ANY KIND, either express or implied. See the License for the
  • specific language governing permissions and limitations under the License.

*

  • Tencent is pleased to support the open source community by making polaris-go available. *
  • Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. *
  • Licensed under the BSD 3-Clause License (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • https://opensource.org/licenses/BSD-3-Clause *
  • Unless required by applicable law or agreed to in writing, software distributed
  • under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  • CONDITIONS OF ANY KIND, either express or implied. See the License for the
  • specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	UDPSize uint16 = 65535
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncConn

type AsyncConn struct {
	ConnBase

	MsgBufMap sync.Map

	WriteChan chan *dns.Msg

	ReadChan chan *RspData
	// contains filtered or unexported fields
}

异步Conn

func (*AsyncConn) Close

func (co *AsyncConn) Close()

清理资源

func (*AsyncConn) Init

func (co *AsyncConn) Init() error

init

func (*AsyncConn) ReceiveUdpPack

func (c *AsyncConn) ReceiveUdpPack()

异步收包

type Conn

type Conn interface {
	Dial(dstIp string, port int) error
	Close()
	ReadMsg() (*dns.Msg, error)
	WriteMsg(m *dns.Msg) error
	SetWriteDeadline(t time.Time) error
	SetReadDeadline(t time.Time) error
}

conn interface

type ConnBase

type ConnBase struct {
	UdpConn *net.UDPConn
	UDPSize uint16
}

发送Conn

func (*ConnBase) Close

func (c *ConnBase) Close()

关闭

func (*ConnBase) Dial

func (c *ConnBase) Dial(dstIp string, port int) error

UDP dial

func (*ConnBase) ReadMsg

func (co *ConnBase) ReadMsg() (*dns.Msg, error)

接收消息

func (*ConnBase) SetReadDeadline

func (co *ConnBase) SetReadDeadline(t time.Time) error

SetReadDeadline

func (*ConnBase) SetWriteDeadline

func (co *ConnBase) SetWriteDeadline(t time.Time) error

SetWriteDeadline

func (*ConnBase) WriteMsg

func (co *ConnBase) WriteMsg(m *dns.Msg) (err error)

发包

type Connector

type Connector struct {
	*plugin.PluginBase
	Timeout      time.Duration
	DialTimeout  time.Duration
	ReadTimeout  time.Duration
	WriteTimeout time.Duration

	Conn *AsyncConn // 用于异步发送

	DnsID uint32

	SideCarIp   string
	SideCarPort int

	GetSyncConnFunc GetNewConnFunc
	// contains filtered or unexported fields
}

SideCar connector

func (*Connector) DeRegisterServiceHandler

func (g *Connector) DeRegisterServiceHandler(key *model.ServiceEventKey) error

DeRegisterEventHandler 反注册事件监听器

func (*Connector) DeregisterInstance

func (g *Connector) DeregisterInstance(instance *model.InstanceDeRegisterRequest) error

DeregisterInstance 同步反注册服务

func (*Connector) Heartbeat

func (g *Connector) Heartbeat(instance *model.InstanceHeartbeatRequest) error

心跳上报

func (*Connector) Init

func (c *Connector) Init(ctx *plugin.InitContext)

初始化

func (*Connector) IsEnable

func (g *Connector) IsEnable(cfg config.Configuration) bool

enable

func (*Connector) Name

func (c *Connector) Name() string

返回Name

func (*Connector) Recv

func (c *Connector) Recv() (*namingpb.DiscoverResponse, error)

异步接收

func (*Connector) RegisterInstance

func (g *Connector) RegisterInstance(request *model.InstanceRegisterRequest) (*model.InstanceRegisterResponse, error)

RegisterInstance 同步注册服务

func (*Connector) RegisterServiceHandler

func (g *Connector) RegisterServiceHandler(svcEventHandler *serverconnector.ServiceEventHandler) error

RegisterServiceHandler 注册服务监听

func (*Connector) ReportClient

func (g *Connector) ReportClient(request *model.ReportClientRequest) (*model.ReportClientResponse, error)

报客户端信息

func (*Connector) Send

func (c *Connector) Send(request *namingpb.DiscoverRequest) error

异步发送

func (*Connector) SyncExchange

func (c *Connector) SyncExchange(m *dns.Msg) (*RspData, time.Duration, error)

同步发送收取包

func (*Connector) SyncGetResourceReq

func (g *Connector) SyncGetResourceReq(request *namingpb.DiscoverRequest) (*namingpb.DiscoverResponse, error)

同步获取资源

func (*Connector) UpdateServers

func (g *Connector) UpdateServers(key *model.ServiceEventKey) error

更新服务端地址 sideCar模式目前无需实现

type GetNewConnFunc

type GetNewConnFunc func() Conn

type MsgBuffer

type MsgBuffer struct {
	ID          uint16
	ExpectedNum uint16
	ReceiveNum  uint16

	MsgArr    []*dns.Msg
	BeginTime int64
}

msg buffer 用于合并包

type RspData

type RspData struct {
	RRArr         []dns.RR
	DetailErrInfo *dns.DetailErrInfoRR
	OpCode        int
	RCode         int
}

返回结果记录结构

func AssembleLogicRspData

func AssembleLogicRspData(msgArr []*dns.Msg) *RspData

组包逻辑

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL