networkevent

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2019 License: Apache-2.0 Imports: 11 Imported by: 14

Documentation

Overview

Copyright (c) 2016-2019 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

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.

Copyright (c) 2016-2019 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

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.

Copyright (c) 2016-2019 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

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.

Copyright (c) 2016-2019 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

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.

Copyright (c) 2016-2019 Uber Technologies, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

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

This section is empty.

Variables

This section is empty.

Functions

func Sort

func Sort(events []*Event)

Sort sorts events in place by timestamp.

Types

type Config

type Config struct {
	LogPath string `yaml:"log_path"`
	Enabled bool   `yaml:"enabled"`
}

Config defines network event configuration.

type Event

type Event struct {
	Name    Name      `json:"event"`
	Torrent string    `json:"torrent"`
	Self    string    `json:"self"`
	Time    time.Time `json:"ts"`

	// Optional fields.
	Peer         string `json:"peer,omitempty"`
	Piece        int    `json:"piece,omitempty"`
	Bitfield     []bool `json:"bitfield,omitempty"`
	DurationMS   int64  `json:"duration_ms,omitempty"`
	ConnCapacity int    `json:"conn_capacity,omitempty"`
}

Event consolidates all possible event fields.

func AddActiveConnEvent

func AddActiveConnEvent(h core.InfoHash, self core.PeerID, peer core.PeerID) *Event

AddActiveConnEvent returns an event for an added active conn from self to peer.

func AddTorrentEvent

func AddTorrentEvent(h core.InfoHash, self core.PeerID, b *bitset.BitSet, connCapacity int) *Event

AddTorrentEvent returns an event for an added torrent with initial bitfield.

func BlacklistConnEvent

func BlacklistConnEvent(h core.InfoHash, self core.PeerID, peer core.PeerID, dur time.Duration) *Event

BlacklistConnEvent returns an event for a blacklisted connection.

func DropActiveConnEvent

func DropActiveConnEvent(h core.InfoHash, self core.PeerID, peer core.PeerID) *Event

DropActiveConnEvent returns an event for a dropped active conn from self to peer.

func Filter

func Filter(events []*Event, names ...Name) []*Event

Filter filters events by name.

func ReceivePieceEvent

func ReceivePieceEvent(h core.InfoHash, self core.PeerID, peer core.PeerID, piece int) *Event

ReceivePieceEvent returns an event for a piece received from peer.

func StripTimestamps

func StripTimestamps(events []*Event) []*Event

StripTimestamps overwrites timestamps in events as empty, allowing clients to check equality of events.

Mutates events in place and returns events for chaining purposes.

func TorrentCancelledEvent

func TorrentCancelledEvent(h core.InfoHash, self core.PeerID) *Event

TorrentCancelledEvent returns an event for a cancelled torrent.

func TorrentCompleteEvent

func TorrentCompleteEvent(h core.InfoHash, self core.PeerID) *Event

TorrentCompleteEvent returns an event for a completed torrent.

func (*Event) JSON

func (e *Event) JSON() string

JSON converts event into a json string primarely for logging purposes

type Name

type Name string

Name defines event names.

const (
	AddTorrent       Name = "add_torrent"
	AddActiveConn    Name = "add_active_conn"
	DropActiveConn   Name = "drop_active_conn"
	BlacklistConn    Name = "blacklist_conn"
	ReceivePiece     Name = "receive_piece"
	TorrentComplete  Name = "torrent_complete"
	TorrentCancelled Name = "torrent_cancelled"
)

Possible event names.

type Producer

type Producer interface {
	Produce(e *Event)
	Close() error
}

Producer emits events.

func NewProducer

func NewProducer(config Config) (Producer, error)

NewProducer creates a new Producer.

type TestProducer

type TestProducer struct {
	sync.Mutex
	// contains filtered or unexported fields
}

TestProducer records all produced events.

func NewTestProducer

func NewTestProducer() *TestProducer

NewTestProducer returns a new TestProducer.

func (*TestProducer) Close

func (p *TestProducer) Close() error

Close noops.

func (*TestProducer) Events

func (p *TestProducer) Events() []*Event

Events returns all currently recorded events.

func (*TestProducer) Produce

func (p *TestProducer) Produce(e *Event)

Produce records e.

Jump to

Keyboard shortcuts

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