New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/s4nat/lamport-clocks

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/s4nat/lamport-clocks

  • v0.0.0-20231104054428-2fdd493d6d2f
  • Source
  • Go
  • Socket score

Version published
Created
Source

Lamport and Vector Clock - readMe

This project simulates a client-server architecture where several clients are registered to a server. Periodically, each client sends messages to the server. Upon receiving a message, the server may either forward the message to all other registered clients or drop the message altogether. The project implements both Lamport's logical clock and Vector clocks to order and manage messages.

Getting Started

Running the simulation

Build the Go program and run it

cd cmd/logical_clock

go build && ./logical_clock

cd cmd/vector_clock

go build && ./vector_clock

Note: For Windows platforms, run the executable file (e.g., logical_clock.exe ).

Overview of the Code

Data Structures

  • server : Represents the main server which listens to client messages and might broadcast them to other clients.
  • client : Represents a client which sends messages to the server and listens for broadcasted messages.
    • message : Represents a message with its metadata including sender, receiver, actual content, and a logical timestamp.

Key Functions

  • NewServer() : Initializes a new server.
    • NewClient() : Initializes a new client.
      • clientSend() : Handles the client-side logic when sending a message. It increments the logical timestamp and sends the message to the server.
        • clientListen() : Handles the client-side logic when listening to messages. It updates its local logical timestamp based on received messages and detects causality violations using vector clocks.
      • listenAndBroadcast() : Handles the server-side logic. It listens to incoming messages from clients, updates its own logical timestamp, and decides whether to broadcast the message to other clients.

Logical Clocks

The program uses two kinds of logical clocks:

  1. Lamport's Logical Clock: It's a simple counter that ensures a total order of events in a distributed system.
  2. Vector Clock: A more complex structure that can capture causality between events. It uses an integer array where each index represents a client.

Understanding the Output

When you run the simulation, you'll observe a series of messages indicating:

  1. Which client has sent a message and its content.
  2. Which messages the server has received and whether it broadcasts them.
  3. Which messages each client receives.

At the end of the simulation, the program will print a list of messages in the order determined by the logical clocks Lamport and V ector Clock - readMe 2

FAQs

Package last updated on 04 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc