models

package
v0.0.0-...-07e86f8 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2019 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Inactive = iota // 0
	Active
	Create
	Update
	Remove
	Removed
)

States in which a SCIONLabAS or connection can be.

View Source
const (
	Parent = iota // 0
	Child
	Core
	Peer
)

Link types

View Source
const (
	Infrastructure = iota // 0
	VM
	Dedicated
	Box
)

Types of SCIONLabASes

View Source
const (
	Pending  = "PENDING"
	Approved = "APPROVED"
)
View Source
const (
	APIContext   = string("scion-coordinator")
	SaltLength   = 80
	SecretLength = 32
)

Variables

This section is empty.

Functions

func BandwidthToCredits

func BandwidthToCredits(bandwidthInKilobits uint64) int64

Converts a bandwidth into credits (10 MegaBits/s=1 Credit)

func DeleteConnReply

func DeleteConnReply(acc *Account, reqID uint64) error

func DeleteConnRequest

func DeleteConnRequest(acc *Account, reqID uint64) error

func DeleteConnectionFromDB

func DeleteConnectionFromDB(connectionId uint64) error

func DeleteJoinReply

func DeleteJoinReply(requester string, reqID uint64) error

func DeleteJoinRequest

func DeleteJoinRequest(requester string, reqID uint64) error

func FindSCIONLabASesByAccountID

func FindSCIONLabASesByAccountID(accountID string) (asStrings []string, err error)

Find SCIONLabASes by AccountID; returns a slice of IA strings

func FindUserByEmail

func FindUserByEmail(email string) (*user, error)

func FindUserByID

func FindUserByID(id string) (*user, error)

func FindUserByVerificationUUID

func FindUserByVerificationUUID(link string) (*user, error)

func LinkTypeString

func LinkTypeString(linkType uint8) string

func RegisterUser

func RegisterUser(accountName, organisation, email, password, first, last string) (*user, error)

This function creates both a new user and a new account and associate them

Types

type ASInfo

type ASInfo struct {
	ISD     addr.ISD
	ASID    addr.AS
	Core    bool
	Account *Account
	Credits int64
	Created time.Time
}

The following struct and functions are used in the mediation API functions

func FindASInfoByIA

func FindASInfoByIA(isdas string) (*ASInfo, error)

func FindASInfosByISD

func FindASInfosByISD(isd addr.ISD) ([]ASInfo, error)

func FindAllASInfos

func FindAllASInfos() ([]ASInfo, error)

func FindCoreASInfosByISD

func FindCoreASInfosByISD(isd addr.ISD) ([]ASInfo, error)

func (*ASInfo) Insert

func (asInfo *ASInfo) Insert() error

func (*ASInfo) ListConnections

func (asInfo *ASInfo) ListConnections() ([]ConnectionWithCredits, error)

Look for all connection to and from this AS and calculates the necessary credits for it

func (*ASInfo) String

func (asInfo *ASInfo) String() string

func (*ASInfo) UpdateCurrency

func (asInfo *ASInfo) UpdateCurrency(CreditsDiff int64) error

Changes the Credits the AS has. CreditsDiff can be negative to subtract and be positive to add Credits

type Account

type Account struct {
	ID           uint64 `orm:"column(id);auto;pk"`
	Name         string
	Organisation string
	AccountID    string `orm:"column(account_id)"`
	Secret       string
	Users        []*user `orm:"reverse(many);index"`
	Created      time.Time
	Updated      time.Time
}

func FindAccountByAccountID

func FindAccountByAccountID(accID string) (*Account, error)

func FindAccountByAccountIDAndSecret

func FindAccountByAccountIDAndSecret(accID, secret string) (*Account, error)

func FindAccountByName

func FindAccountByName(name string) (*Account, error)

func FindAccountByUserEmail

func FindAccountByUserEmail(email string) (*Account, error)

func (*Account) Delete

func (a *Account) Delete() error

func (*Account) Upsert

func (a *Account) Upsert() error

type AttachmentPoint

type AttachmentPoint struct {
	ID          uint64        `orm:"column(id);auto;pk"`
	HasVPN      bool          `orm:"column(has_vpn);default(1)"`
	VPNPort     uint16        `orm:"column(vpn_port);default(1194)"`
	VPNIP       string        `orm:"column(vpn_ip)"`
	StartVPNIP  string        `orm:"column(start_vpn_ip)"`
	EndVPNIP    string        `orm:"column(end_vpn_ip)"`
	AS          *SCIONLabAS   `orm:"column(as_id);rel(one);on_delete(cascade)"`
	Connections []*Connection `orm:"reverse(many);index"` // List of Connections
}

func (*AttachmentPoint) Delete

func (ap *AttachmentPoint) Delete() error

func (*AttachmentPoint) Insert

func (ap *AttachmentPoint) Insert() error

func (*AttachmentPoint) Update

func (ap *AttachmentPoint) Update() error

type ConnReply

type ConnReply struct {
	ID          uint64   `orm:"column(id);auto;pk"`
	RequestID   uint64   `orm:"column(request_id)"`
	Info        string   // free form text for the reply
	Account     *Account `orm:"rel(fk)"` // account which should receive the connection reply
	Status      string
	RespondIA   string `orm:"column(respond_ia)"`
	RequestIA   string `orm:"column(request_ia)"`
	Certificate string `orm:"type(text)"`
	OverlayType string
	IP          string `orm:"column(ip)"`
	Port        uint64
	MTU         uint64 `orm:"column(mtu)"` // bytes
	Bandwidth   uint64 // kbps
}

func FindConnRepliesByRequestIA

func FindConnRepliesByRequestIA(isdas string) ([]ConnReply, error)

func (*ConnReply) Insert

func (cr *ConnReply) Insert() error

type ConnRequest

type ConnRequest struct {
	ID                   uint64   `orm:"column(id);auto;pk"`
	RequestID            uint64   `orm:"column(request_id)"`
	Account              *Account `orm:"rel(fk)"` // account sending the connection request
	Status               string
	RequestIA            string `orm:"column(request_ia)"`
	RespondIA            string `orm:"column(respond_ia)"`
	RequesterCertificate string `orm:"type(text)"`
	Info                 string // free form text motivation for the request
	OverlayType          string
	IP                   string `orm:"column(ip)"`
	Port                 uint64
	MTU                  uint64 `orm:"column(mtu)"` // bytes
	Bandwidth            uint64 // kbps
	LinkType             string
	Timestamp            string // UTC ISO 8601 format string, 1s precision
	Signature            string
}

func FindConnRequest

func FindConnRequest(acc *Account, reqID uint64) (*ConnRequest, error)

func FindOpenConnRequestsByRespondIA

func FindOpenConnRequestsByRespondIA(isdas string) ([]ConnRequest, error)

func (*ConnRequest) Insert

func (cr *ConnRequest) Insert() error

func (*ConnRequest) Update

func (cr *ConnRequest) Update() error

type Connection

type Connection struct {
	ID            uint64           `orm:"column(id);auto;pk"`
	JoinAS        *SCIONLabAS      `orm:"column(join_as);rel(fk)"`    // AS which initiated the connection
	RespondAP     *AttachmentPoint `orm:"column(respond_ap);rel(fk)"` // AS which accepted the connection
	JoinIP        string           `orm:"column(join_ip)"`            // IP address used for the joining AS
	RespondIP     string           `orm:"column(respond_ip)"`         // IP address used for the responding AS
	JoinBRID      uint16           `orm:"column(join_br_id)"`         // ID of the joining border router, Port = StartPort + BRID
	RespondBRID   uint16           `orm:"column(respond_br_id)"`      // ID of the responding AS's border router
	Linktype      uint8            // role of the responding AS
	IsVPN         bool             `orm:"column(is_vpn)"`
	JoinStatus    uint8
	RespondStatus uint8
	Created       time.Time
	Updated       time.Time
}

func (*Connection) Delete

func (cn *Connection) Delete() error

func (*Connection) GetJoinAS

func (cn *Connection) GetJoinAS() *SCIONLabAS

func (*Connection) GetRespondAP

func (cn *Connection) GetRespondAP() *AttachmentPoint

func (*Connection) GetRespondAS

func (cn *Connection) GetRespondAS() *SCIONLabAS

func (*Connection) Insert

func (cn *Connection) Insert() error

func (*Connection) IsCurrentConnection

func (cn *Connection) IsCurrentConnection() bool

IsCurrentConnection returns false if this Connection is scheduled to be removed from the DB, due to a reconfiguration in which another AP is taking the user AS. Any given AS has 0-1 active connection and 0-N non active ones at a given moment.

func (*Connection) JoinBindIP

func (cn *Connection) JoinBindIP() string

func (*Connection) RespondBindIP

func (cn *Connection) RespondBindIP() string

func (*Connection) Update

func (cn *Connection) Update() error

type ConnectionInfo

type ConnectionInfo struct {
	ID                   uint64 // Used to find the BorderRouter
	NeighborISD          addr.ISD
	NeighborAS           addr.AS
	NeighborIP           string
	NeighborUser         string
	NeighborStatus       uint8
	LocalIP              string
	BindIP               string
	BRID                 uint16
	NeighborBRID         uint16
	NeighborPort         uint16 // port of the neighbor's border router
	LocalPort            uint16 // port of the local border router
	Linktype             uint8  //"PARENT","CHILD"
	IsVPN                bool
	Status               uint8
	KeepASStatusOnUpdate bool // true if this WAS a connection to an AP, but it needs to be deleted in the AP
	UpdatedOn            time.Time
}

Contains all info needed to populate the topology file

func FindRespondConnectionInfoByIA

func FindRespondConnectionInfoByIA(ia string) ([]ConnectionInfo, error)

Takes the IA string as an input and returns all ConnectionInfos where the AS is the AP

func OnlyCurrentConnections

func OnlyCurrentConnections(cns []ConnectionInfo) []ConnectionInfo

func OnlyNotCurrentConnections

func OnlyNotCurrentConnections(cns []ConnectionInfo) []ConnectionInfo

func (*ConnectionInfo) IsCurrentConnection

func (cn *ConnectionInfo) IsCurrentConnection() bool

IsCurrentConnection returns false if this Connection is scheduled to be removed from the DB, due to a reconfiguration in which another AP is taking the user AS. Any given AS has 0-1 active connection and 0-N non active ones at a given moment.

type ConnectionWithCredits

type ConnectionWithCredits struct {
	ISD           addr.ISD // ISD of the other AS
	AS            addr.AS  // the other AS
	CreditBalance int64    // How much credits the connection costs / yields
	Bandwidth     uint64   // The bandwidth in kb/s
	IsOutgoing    bool     // false = the other AS has to pay, true = the other AS gets credits
	Timestamp     string   // The creation time of the connection
}

Stores the connection info from an AS to another AS

type ISDLocation

type ISDLocation struct {
	ID        uint64   `orm:"column(id);auto;pk"`
	ISD       addr.ISD `orm:"column(isd)"`
	Country   string
	Continent string
}

func FindISDbyContinent

func FindISDbyContinent(continent string) (*ISDLocation, error)

func FindISDbyCountry

func FindISDbyCountry(country string) (*ISDLocation, error)

func FindISDbyID

func FindISDbyID(id addr.ISD) (*ISDLocation, error)

func (*ISDLocation) Insert

func (il *ISDLocation) Insert() error

func (*ISDLocation) TableName

func (il *ISDLocation) TableName() string

func (*ISDLocation) Update

func (il *ISDLocation) Update() error

type JoinReply

type JoinReply struct {
	ID                   uint64 `orm:"column(id);auto;pk"`
	RequestID            uint64 `orm:"column(request_id)"`
	Info                 string // free form text for the reply
	RequesterID          string `orm:"column(requester_id)"` // the string to identify which account made the request
	Status               string
	JoiningIA            string `orm:"column(joining_ia)"`
	IsCore               bool   // whether the new AS joins as core
	RespondIA            string `orm:"column(respond_ia)"`
	JoiningIACertificate string `orm:"column(joining_ia_certificate);type(text)"`    // certificate of the newly joining AS
	RespondIACertificate string `orm:"column(responding_ia_certificate);type(text)"` // certificate of the responding AS
	TRC                  string `orm:"column(trc);type(text)"`
}

func FindJoinReply

func FindJoinReply(requester string, reqID uint64) (*JoinReply, error)

func (*JoinReply) Insert

func (jr *JoinReply) Insert() error

type JoinRequest

type JoinRequest struct {
	ID            uint64   `orm:"column(id);auto;pk"`
	RequestID     uint64   `orm:"column(request_id)"`
	Info          string   // free form text for the reply
	ISDToJoin     addr.ISD `orm:"column(isd_to_join)"`       // the ISD that the sender wants to join
	JoinAsACoreAS bool     `orm:"column(join_as_a_core_as)"` // whether to join the ISD as a core AS
	RequesterID   string   `orm:"column(requester_id)"`      // the key to identify which account made the request
	RespondIA     string   `orm:"column(respond_ia)"`        // the ISD-AS which should respond to the request
	SigPubKey     string   // signing public key
	EncPubKey     string   // encryption public key
	Status        string
}

func FindJoinRequest

func FindJoinRequest(requester string, reqID uint64) (*JoinRequest, error)

func FindOpenJoinRequestsByIA

func FindOpenJoinRequestsByIA(isdas string) ([]JoinRequest, error)

func (*JoinRequest) Insert

func (jr *JoinRequest) Insert() error

func (*JoinRequest) Update

func (jr *JoinRequest) Update() error

type M

type M map[string]interface{}

type SCIONBox

type SCIONBox struct {
	ID             uint64 `orm:"column(id);auto;pk"`
	MAC            string `orm:"column(mac)"`
	UserEmail      string
	ISD            addr.ISD `orm:"column(isd);default(0)"`
	AS             addr.AS  `orm:"column(as);default(0)"`
	InternalIP     string   `orm:"column(internal_ip)"`
	Shipping       string
	OpenPorts      uint16 `orm:"default(0)"` // Number of free ports UDP ports starting from StartPort
	StartPort      uint16 `orm:"default(50000)"`
	UpdateRequired bool
	Created        time.Time
	Updated        time.Time
}

func FindSCIONBoxByEMail

func FindSCIONBoxByEMail(userEmail string) (*SCIONBox, error)

func FindSCIONBoxByIAint

func FindSCIONBoxByIAint(isd addr.ISD, As addr.AS) (*SCIONBox, error)

func FindSCIONBoxByMAC

func FindSCIONBoxByMAC(mac string) (*SCIONBox, error)

func (*SCIONBox) Insert

func (sb *SCIONBox) Insert() error

func (*SCIONBox) Remove

func (sb *SCIONBox) Remove() error

func (*SCIONBox) TableName

func (sb *SCIONBox) TableName() string

func (*SCIONBox) Update

func (sb *SCIONBox) Update() error

type SCIONLabAS

type SCIONLabAS struct {
	ID          uint64           `orm:"column(id);auto;pk"`
	UserEmail   string           // Owner of the AS
	PublicIP    string           `orm:"column(public_ip)"` // IP address of the AS; can be empty in case of VPN-based setups
	StartPort   uint16           // First port used for border routers
	ISD         addr.ISD         `orm:"column(isd);default(0)"` // 0 means no ISD is joined
	ASID        addr.AS          `orm:"column(as_id)"`
	Core        bool             `orm:"default(false)"` // Is this SCIONLabAS a core AS
	Label       string           // Optional label for this AS (can be chosen by the user)
	Status      uint8            `orm:"default(0)"` // Status of the AS: Active, Create, ...
	Type        uint8            `orm:"default(0)"` // Type of the AS: Box, VM, Dedicated, ...
	AP          *AttachmentPoint `orm:"null;reverse(one)"`
	Credits     int64            // Credits in virtual credit system
	Branch      string           `orm:"default(scionlab)"` // Update branch the AS is tracking ("scionlab", "scionlab_testing", "none")
	Created     time.Time        // When the AS was first created
	Updated     time.Time        // Last time the configuration was modified or the AS called `ConfirmUpdate`
	Connections []*Connection    `orm:"reverse(many)"` // List of Connections
	RemapStatus string           `orm:"size(1000);type(json);null"`
	ConfVersion uint             `orm:"default(0)"`
}

TODO(philippmao, mlegner): Link SCIONLabAS to user model? TODO(mlegner): Maybe it would make more sense to replace the user by an account here

func FindAllAPsByISD

func FindAllAPsByISD(isd addr.ISD) ([]*SCIONLabAS, error)

Returns all Attachment Point ASes in the given ISD

func FindPotentialNeighbors

func FindPotentialNeighbors(isd addr.ISD) ([]SCIONLabAS, error)

Find Potential Neighbors for the Box

func FindSCIONLabASByASID

func FindSCIONLabASByASID(asID addr.AS) (*SCIONLabAS, error)

func FindSCIONLabASByASInfo

func FindSCIONLabASByASInfo(asInfo ASInfo) (*SCIONLabAS, error)

func FindSCIONLabASByIAInt

func FindSCIONLabASByIAInt(isd addr.ISD, asID addr.AS) (*SCIONLabAS, error)

Find SCIONLabAS by the ISD AS int

func FindSCIONLabASByIAString

func FindSCIONLabASByIAString(ia string) (*SCIONLabAS, error)

Find SCIONLabAS by the IA string

func FindSCIONLabASByUserEmailAndASID

func FindSCIONLabASByUserEmailAndASID(email string, asID addr.AS) (*SCIONLabAS, error)

Find a single SCIONLabAS by UserEmail and the AS ID

func FindSCIONLabASesByIP

func FindSCIONLabASesByIP(ip string) ([]SCIONLabAS, error)

Find SCIONLabAS by the Public IP TODO(mlegner): The PublicIP field can be empty; we need to be careful with this function

func FindSCIONLabASesByUserEmail

func FindSCIONLabASesByUserEmail(email string) ([]SCIONLabAS, error)

Find SCIONLabASes by UserEmail

func FindSCIONLabASesByUserEmailAndType

func FindSCIONLabASesByUserEmailAndType(email string, Type uint8) ([]SCIONLabAS, error)

Find SCIONLabASes by UserEmail and Type

func FindSCIONLabAsesByISD

func FindSCIONLabAsesByISD(isd addr.ISD) ([]SCIONLabAS, error)

func GetAllAPs

func GetAllAPs() ([]*SCIONLabAS, error)

Returns all Attachment Point ASes

func GetAllAPsByISD

func GetAllAPsByISD(isd addr.ISD) ([]SCIONLabAS, error)

Find All Active Attachment Points in an ISD

func (*SCIONLabAS) AreIDsFromScionLab

func (as *SCIONLabAS) AreIDsFromScionLab() bool

AreIDsFromScionLab checks the ISD and AS numbers against the standard you can find in https://github.com/scionproto/scion/wiki/ISD-and-AS-numbering , and returns true if they are okay for SCIONLab; false otherwise.

func (*SCIONLabAS) BindIP

func (as *SCIONLabAS) BindIP(isVPN bool, connectionIP string) string

This function determines the BindIP address used for the border router of a given connection TODO(mlegner): This should be replaced by an iptables rule and simply the ServerIP here

func (*SCIONLabAS) Delete

func (as *SCIONLabAS) Delete() error

func (*SCIONLabAS) DeleteConnectionFromDB

func (as *SCIONLabAS) DeleteConnectionFromDB(cnInfo *ConnectionInfo) error

Delete a connection between specified ASes

func (*SCIONLabAS) FlagAllConnectionsToAPToBeDeleted

func (as *SCIONLabAS) FlagAllConnectionsToAPToBeDeleted(apIA string) error

func (*SCIONLabAS) GetConnectionInfo

func (as *SCIONLabAS) GetConnectionInfo() ([]ConnectionInfo, error)

Returns a list of ConnectionInfo for all connections of the AS

func (*SCIONLabAS) GetFreeBRID

func (as *SCIONLabAS) GetFreeBRID() (uint16, error)

func (*SCIONLabAS) GetFreeVPNIP

func (as *SCIONLabAS) GetFreeVPNIP() (string, error)

TODO(mlegner): Avoid signed/unsigned casting; could be problematic if huge IP ranges are used

func (*SCIONLabAS) GetJoinConnectionInfo

func (as *SCIONLabAS) GetJoinConnectionInfo() ([]ConnectionInfo, error)

Returns a list of ConnectionInfo where the AS is the joining AS

func (*SCIONLabAS) GetJoinConnectionInfoToAS

func (as *SCIONLabAS) GetJoinConnectionInfoToAS(apIA string) ([]ConnectionInfo, error)

Returns the connection of an AP to the specified AS TODO(mlegner): This function assumes that there can only be one connection between an AS/AP pair

func (*SCIONLabAS) GetJoinConnections

func (as *SCIONLabAS) GetJoinConnections() ([]*Connection, error)

Only returns the connections of the AS in its function as the joining AS

func (*SCIONLabAS) GetJoinNotRemovedConnections

func (as *SCIONLabAS) GetJoinNotRemovedConnections() ([]*Connection, error)

GetJoinActiveConnections is similar to GetJoinConnections but it filters the connections scheduled to be removed from APs

func (*SCIONLabAS) GetMappingStatus

func (as *SCIONLabAS) GetMappingStatus() (map[string]interface{}, error)

GetMappingStatus returns the mapping status map that was stored in the DB for this AS

func (*SCIONLabAS) GetPortNumberFromBRID

func (as *SCIONLabAS) GetPortNumberFromBRID(brID uint16) uint16

func (*SCIONLabAS) GetRemapChallenge

func (as *SCIONLabAS) GetRemapChallenge() (string, error)

GetRemapChallenge returns the stored challenge or a new one otherwise.

func (*SCIONLabAS) GetRespondConnectionInfo

func (as *SCIONLabAS) GetRespondConnectionInfo() ([]ConnectionInfo, error)

Returns a list of ConnectionInfo where the AS is the responding AS

func (*SCIONLabAS) GetRespondConnectionInfoToAS

func (as *SCIONLabAS) GetRespondConnectionInfoToAS(otherAS addr.AS) ([]ConnectionInfo, error)

GetRespondConnectionInfoToAS returns a list where the AS is the responding AS (the AP), and the other AS is the user AS attached to it.

func (*SCIONLabAS) GetRespondConnections

func (as *SCIONLabAS) GetRespondConnections() ([]*Connection, error)

Only returns the connections of the AS in its function as an AP

func (*SCIONLabAS) IA

func (as *SCIONLabAS) IA() addr.IA

func (*SCIONLabAS) IAString

func (as *SCIONLabAS) IAString() string

func (*SCIONLabAS) Insert

func (as *SCIONLabAS) Insert() error

func (*SCIONLabAS) ServerIP

func (as *SCIONLabAS) ServerIP() string

This function determines the IP address that are used for different SCION servers (CS, BS, PS)

func (*SCIONLabAS) SetMappingStatusAndSave

func (as *SCIONLabAS) SetMappingStatusAndSave(status map[string]interface{}) error

SetMappingStatusAndSave JSON serializes the dictionary, stores it in the AS and writes to DB

func (*SCIONLabAS) String

func (as *SCIONLabAS) String() string

func (*SCIONLabAS) TableName

func (as *SCIONLabAS) TableName() string

func (*SCIONLabAS) Update

func (as *SCIONLabAS) Update() error

func (*SCIONLabAS) UpdateASAndConnection

func (as *SCIONLabAS) UpdateASAndConnection(cn *Connection) error

func (*SCIONLabAS) UpdateASAndConnectionFromJoinConnInfo

func (as *SCIONLabAS) UpdateASAndConnectionFromJoinConnInfo(cnInfo *ConnectionInfo) error

Update both the SCIONLabAS and Connection tables

func (*SCIONLabAS) UpdateDBConnectionFromJoinConnInfo

func (as *SCIONLabAS) UpdateDBConnectionFromJoinConnInfo(cnInfo *ConnectionInfo) error

Update the Status of a Connection using a ConnectionInfo Object

type Session

type Session struct {
	UserID       uint64
	Email        string
	First        string
	Last         string
	Organisation string
	XSRFToken    string
	HasLoggedIn  bool
	IsAdmin      bool
	Error        string // errors to display while rendering the template
}

Jump to

Keyboard shortcuts

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