Skip to content

Instantly share code, notes, and snippets.

View zeroFruit's full-sized avatar
🎯
Focusing

JooHyung Kim zeroFruit

🎯
Focusing
View GitHub Profile
@zeroFruit
zeroFruit / host.go
Created October 31, 2020 12:19
Modeling the Internet from the scratch: Link-layer, LAN, Switch - Code snippet: Network Topology
package link
type Link struct {
cost uint
ep1 EndPoint
ep2 EndPoint
}
func (l *Link) AttachEndpoint(ep EndPoint) error {
...
@zeroFruit
zeroFruit / addr.go
Created October 31, 2020 12:21
Modeling the Internet from the scratch: Link-layer, LAN, Switch - Code snippet: MAC address
package link
type Addr string
@zeroFruit
zeroFruit / host.go
Last active October 31, 2020 12:22
Modeling the Internet from the scratch: Link-layer, LAN, Switch - Code snippet: Host, Interface
package link
type Transmitter interface {
Transmit(frame []byte) error
}
type Interface interface {
Transmitter
EndPoint
Address() types.HwAddr
@zeroFruit
zeroFruit / swch.go
Created October 31, 2020 12:24
Modeling the Internet from the scratch: Link-layer, LAN, Switch - Code snippet: Switch
type ForwardEntry struct {
// Incoming is port id attached to switch
Incoming Id
// Addr is destination node address
Addr types.HwAddr
// Time is timestamp when this entry is created
Time time.Time
}
@zeroFruit
zeroFruit / port.go
Created October 31, 2020 12:25
Modeling the Internet from the scratch: Link-layer, LAN, Switch - Code snippet: Port
// Port can transmit data and can be point of link. But it has no hardware
// address. Before using Port, it must register its own Id
type Port interface {
Transmitter
EndPoint
Register(id Id)
Registered() bool
}
@zeroFruit
zeroFruit / swch.go
Created October 31, 2020 12:28
Modeling the Internet from the scratch: Link-layer, LAN, Switch - Code snippet: Switch Forwarding
// Forward receives id of port it receives frame, address of sender
// and frame to send to receiver. Based on id and address it determines whether to
// broadcast frame or forward it to others, otherwise just discard frame.
func (s *Switch) Forward(incoming Id, frame na.Frame) error {
s.Table.Update(incoming, frame.Src)
frm, err := s.frmEnc.Encode(frame)
if err != nil {
return err
}
@zeroFruit
zeroFruit / network.go
Created October 31, 2020 12:30
Modeling the Internet from the scratch: Link-layer, LAN, Switch - Code snippet: Build network-1
func Build() (host1 *link.Host, host2 *link.Host, host3 *link.Host,
swch1 *link.Switch, swch2 *link.Switch) {
// setup node
host1 = link.NewHost()
host2 = link.NewHost()
host3 = link.NewHost()
swch1 = link.NewSwitch()
swch2 = link.NewSwitch()
}
@zeroFruit
zeroFruit / network.go
Created October 31, 2020 12:31
Modeling the Internet from the scratch: Link-layer, LAN, Switch - Code snippet: Build network-2
func Build() (host1 *link.Host, host2 *link.Host, host3 *link.Host,
swch1 *link.Switch, swch2 *link.Switch) {
// setup node
...
// setup interface
intf1 := link.NewInterface(40001, link.AddrFromStr("11-11-11-11-11-11"), host1)
attachInterface(host1, intf1)
intf2 := link.NewInterface(40002, link.AddrFromStr("22-22-22-22-22-22"), host2)
attachInterface(host2, intf2)
@zeroFruit
zeroFruit / network.go
Created October 31, 2020 12:33
Modeling the Internet from the scratch: Link-layer, LAN, Switch - Code snippet: Build network-3
func Build() (host1 *link.Host, host2 *link.Host, host3 *link.Host,
swch1 *link.Switch, swch2 *link.Switch) {
// setup node
// setup interface
...
// setup link
link1 := link.NewLink(1)
attachLink(intf1, link1)
attachLink(sp11, link1)
@zeroFruit
zeroFruit / Cosmovisor directory structure.txt
Created July 5, 2022 00:27
Cosmos Dev Series: Cosmos-SDK-based Blockchain Upgrade
. # $DAEMON_HOME
β”œβ”€β”€ config
β”œβ”€β”€ cosmovisor
β”‚ β”œβ”€β”€ current # symbolic link
β”‚ β”œβ”€β”€ genesis
β”‚ β”‚ └── bin
β”‚ β”‚ └── simappd # $DAEMON_NAME
β”‚ └── upgrades
β”‚ └── v2.0.0 # upgrade name
β”‚ └── bin