-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmsg.go
executable file
·87 lines (72 loc) · 1.93 KB
/
msg.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//
// Copyright (c) 2010 - 2012 Yigong Liu
//
// Distributed under New BSD License
//
package router
import (
"fmt"
"reflect"
)
//a message struct for propagating router's namespace changes (chan attachments or detachments)
type ChanInfoMsg struct {
Info []*ChanInfo
}
//a message struct holding information about id and its associated ChanType
type ChanInfo struct {
Id Id
ChanType reflect.Type
ElemType *chanElemTypeData
}
func (ici ChanInfo) String() string {
return fmt.Sprintf("%v_%v", ici.Id, ici.ElemType)
}
//store marshaled information about ChanType
type chanElemTypeData struct {
//full name of elem type: pkg_path.data_type
FullName string
//the following should be string encoding of the elem type
//it contains info for both names/types.
//e.g. for struct, it could be in form of "struct{fieldName:typeName,...}"
TypeEncoding string
}
func (et chanElemTypeData) String() string {
return fmt.Sprintf("[%v_%v]", et.FullName, et.TypeEncoding)
}
//the generic message wrapper
type genericMsg struct {
Id Id
Data interface{}
}
//a message struct containing information about remote router connection
type ConnInfoMsg struct {
ConnInfo string
Error string
Id Id
Type string //async/flowControlled/raw
}
//recver-router notify sender-router which channel are ready to recv how many msgs
type ChanReadyInfo struct {
Id Id
Credit int
}
func (cri ChanReadyInfo) String() string {
return fmt.Sprintf("%v_%v", cri.Id, cri.Credit)
}
type ConnReadyMsg struct {
Info []*ChanReadyInfo
}
type BindEventType int8
const (
PeerAttach BindEventType = iota
PeerDetach
EndOfData
)
//a message struct containing information for peer (sender/recver) binding/connection.
//sent by router whenever peer attached or detached.
// Type: the type of event just happened: PeerAttach/PeerDetach/EndOfData
// Count: how many peers are still bound now
type BindEvent struct {
Type BindEventType
Count int //total attached
}