Running Haskell Servant Behind Tor Hidden Services

Here is the build-depends section:

  build-depends:       base >= 4.7 && < 5,
                       base-compat,
                       servant,
                       servant-server,
                       warp,
                       wai,
                       aeson,
                       aeson-compat,
                       network-anonymous-tor,
                       network

Here is a minimal example:

{-# LANGUAGE DataKinds     #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeOperators #-}
module Lib
    ( main
    ) where

import           Prelude                  ()
import           Prelude.Compat

import           Control.Concurrent
import           Data.Aeson
import           GHC.Generics
import qualified Network.Anonymous.Tor    as T
import           Network.Socket
import           Network.Wai
import           Network.Wai.Handler.Warp
import           Servant
import           System.IO

data Event = Event {
    id :: Int
  } deriving (Eq, Show, Generic)

instance ToJSON Event

events :: [Event]
events = [
    Event 1,
    Event 2
  ]

type API = "events" :> Get '[JSON] [Event]

server :: Server API
server = return events

proxy :: Proxy API
proxy = Proxy

application :: Application
application = serve proxy server

main :: IO ()
main = T.withSession 9151 withinSession
  where
    withinSession :: Socket -> IO ()
    withinSession sock = do
      forkIO $ run 8081 application
      onion <- T.mapOnion sock 80 8081 False Nothing
      print onion
      hWaitForInput stdin (-1)
      putStrLn "Done!"
      return ()

It prints a hidden service address like this:

Base32String "RANDOMSTRING"

It quits if you press a key.

You need Tor Browser Bundle running before you run the above code. This is so that the above program connects to Tor and starts an ephemeral hidden service.

After you run the above code, you can access the hidden service after a few minutes (it takes time for hidden service directories to update) by going to http://RANDOMSTRING.onion on your Tor Browser Bundle and you will see this:

Tor Browser_542

It can also work with other Haskell web frameworks. This guy who wrote the library to connect to tor control port has also written similar libraries for I2P connectivity.

Have fun writing web applications that cannot be censored!

Indian Exceptionalism

I have met many fellow Indians who think to have so many Silicon Valley CEOs of the Indian origin, and not say the Chinese origin is somehow proof that the Indians are exceptional.

I think this is a shaky ground to place our pride (if any) on because,

  1. Western society is in a “we are not racist” mode. Everyone there is trying hard to tell each other how they are not racist. So they engage in Tokenism: “Tokenism is the policy and practice of making a perfunctory gesture towards the inclusion of members of minority groups”. In such a milieu becoming anointed as the CEO because you have more melanin, or because of your genitalia, is nothing to brag about.
  2. Having geniuses in a billion member strong group of people is inevitable and nothing remarkable, regardless of whether intelligence is genetic/social in origin.

So perhaps we need to cut down on our jingoism.

 

Boltzmann brains beget Boltzmann

The paradox so far:

The number of particles required to construct a human brain is far fewer than the number of particles required to construct an entire universe with billions of minds in close proximity. Therefore single brains ought to be more likely than universes with billions of brains within them. Yet, we find ourselves in a universe with billions of minds in close proximity.

Much suffering has come from this arrangement, due to the violence that we inflict upon each other. But, to many minds, the proximity of these abusive lesser minds is preferable to the loneliness of being separated from similar minds.

There is a certain benevolence to this form of consciousness. Some attribute this benevolence to a single mind, others attribute it to nature of being itself.

I have a hard time imagining how a single mind would be able to gather enough resources to construct a universe with the right set of starting conditions so that minds that can understand such a universe is begotten within it.

But even if such a possibility were to be entertained, it would mean that mind is limited in capabilities. Because every instance of proto-creativity exhibited by the universe is aided by statistical and evolutionary solutions. There is no design except perhaps in a vague abstract way e.g. about the initial conditions. So whatever led to all this was limited in what it could make/become.

Watchmen

Audio

Whatever happened to the American Dream? It came true. You’re looking at it. Greg Johnson and John Morgan join Richard to discuss the universe of Watchmen and what it reveals about modern America, the contractions of liberals, and the implicit “fascist” mentality that underlies Superhero myths.

Cross-posted from here. This is an excellent analysis of conservatism-vs-liberalism in the context of the Watchmen graphic novels and modern USA.

Inside the mind of a master procrastinator | Tim Urban

My rational decision maker has figured out what not to bet my hard work on. Since 99% of everything is crap(sturgeon’s law), almost everything is not worth working hard on.

It is easy to tell if an endeavor would fail as soon as you start doing it. But I just attempt them anyway (with procrastination) in the hopes that it will help me built a relationship with the teammates I fail with. I don’t. Failure results in teammates hating each other and looking for scapegoats, and my personality (and procrastination) is ideal for scapegoating.

So I kept getting scapegoated and I moved on until I realized I am more productive if I attempt the simplest possible endeavor which requires the least amount of teamwork (so as to avoid scapegoating and also cost of failure). But by then I had also realized there are more idiots willing to part with their money by investing in sure-fail ideas. So I work for such idiots and their small teams and try to avoid being scapegoated which procrastinating. I think this is the optimal solution.

I do not need an instant gratification monkey. But since life is what happens when you are making other plans, some amount of instant gratification is necessary to enjoy this short life.

Khaldun-Quigley-Girard-Friedman model of evolution of civilizations.

DISCLAIMER: Most of this post is plagiarized. We have to care about these ideas more than their original authors. I take no credit for any of this.

In this post, I will mix the works of Ibn Khaldun, Carroll Quigley, Rene Girard and George Friedman, and use their ideas to come up with how human civilizations will look like in the near-future. This can be a model for future regime changes and overthrowing of the Establishment.

Khaldun model

Ibn Khaldun was an Islamic historian who like Carroll Quigley had ideas about the evolution of civilizations.

One of the most important concepts in Ibn Khaldun’s theory of history was Asabiyyah, the social glue that binds individuals into cohesive social groups. Groups wielding greater Asabiyyah impose their will on (if not defeat outright) groups possessing lesser Asabiyyah. But how do groups acquire Asabiyyah and why do they lose it?

Ibn Khaldun argued that the Desert was the crucible of Asabiyyah. Only groups that have high Asabiyyah can survive and thrive in this harsh environment. In contrast, in the urban civilization, Asabiyyah is gradually degraded, until they lose their ability for concerted collective action.

This is why Ibn Khaldun says, go to the desert. (This is what he himself did – when he decided to rebel against one of the rulers of North African states, he went into the desert and organized a Berber uprising.)

But there is a problem. While tribal-level Asabiyyah is a great social glue, making each tribe an effective war machine, a Leader needs to unify all desert tribes to defeat the establishment. In order to bind the tribes into a single force, tribal Asabiyyah is not enough. Another kind of social glue is necessary.

Ibn Khaldun says that this Leader needs religion. It is the religion that has the potential to weld disparate tribes (and more generally, ethnic groups) into a cohesive force. Perhaps the most famous example is the rise of Islam when Prophet Muhammad united the tribes of Arab Bedouins, which his successors lead to conquests from Spain in the West to what is now western China in the East. Romanized Christianity (i.e. post-Nicene council) took control during the falling Roman civilization and unified Europe for thousands of years. Genghis Khan unified the tribes of Mongols under a religion about the Great Tengri.

Ibn Khaldun argues that each dynasty (or civilization) has within itself the seeds of its own downfall. He explains that ruling houses tend to emerge on the peripheries of great empires and use the much stronger Asabiyyah present in those areas to their advantage, in order to bring about a change in leadership. This implies that the new rulers are at first considered “barbarians” by comparison to the old ones. As they establish themselves at the center of their empire, they become increasingly lax, less coordinated, disciplined and watchful, and more concerned with maintaining their new power and lifestyle at the centre of the empire—i.e, their internal cohesion and ties to the original peripheral group, the Asabiyyah, dissolves into factionalism and individualism, diminishing their capacity as a political unit. Thus, conditions are created wherein a new dynasty can emerge at the periphery of their control, grow strong, and effect a change in leadership, beginning the cycle anew.

Quigley Model

Carroll Quigley was a Harvard-educated historian who taught US President Bill Clinton. Quigley’s model is similar to Khaldun but Quigley does not recognize religion/Asabiyyah as having a part to play in evolution. He writes in Tragedy and Hope:

As we look at the three ages forming the central portion of the life cycle of a civilization, we can see a common pattern. The Age of Expansion is generally marked by four kinds of expansion: (1) of the population, (2) of geographic area, (3) of production, and (4) of knowledge. The expansion of production and the expansion of knowledge give rise to the expansion of population, and the three of these together give rise to the expansion of geographic extent. This geographic expansion is of some importance because it gives the civilization a kind of nuclear structure made up of an older core area (which had existed as part of the civilization even before the period of expansion) and a newer peripheral area (which became part of the civilization only in the period of expansion and later). If we wish, we can make, as an additional refinement, a third, semi-peripheral area between the core area and the fully peripheral area.

These various areas are readily discernible in various civilizations of the past and have played a vital role in the historic change in these civilizations. In Mesopotamian Civilization (6000 B.C. -300 B.C.) the core area was the lower valley of Mesopotamia; the semi-peripheral area was the middle and upper valley, while the peripheral area included the highlands surrounding this valley, and more remote areas like Iran, Syria, and even Anatolia. The core area of Cretan Civilization (3500 B.C.-l 100 B.C.) was the island of Crete, while the peripheral area included the Aegean islands and the Balkan coasts. In Classical Civilization, the core area was the shores of the Aegean Sea; the semi- peripheral area was the rest of the northern portion of the eastern Mediterranean Sea, while the peripheral area covered the rest of the Mediterranean shores and ultimately Spain, North Africa, and Gaul. In Canaanite Civilization (2200 B.C. -100 B.C.) the core area was the Levant, while the peripheral area was in the western Mediterranean at Tunis, western Sicily, and eastern Spain. The core area of Western Civilization (A.D. 400 to sometime in the future) has been the northern half of Italy, France, the extreme western part of Germany, and England; the semi-peripheral area has been central, eastern, and southern Europe and the Iberian peninsula, while the peripheral areas have included North and South America, Australia, New Zealand, South Africa, and some other areas.

This distinction of at least two geographic areas in each civilization is of major importance. The process of expansion, which begins in the core area, also begins to slow up in the core at a time when the peripheral area is still expanding. In consequence, by the latter part of the Age of Expansion, the peripheral areas of a civilization tend to become wealthier and more powerful than the core area. Another way of saying this is that the core passes from the Age of Expansion to the Age of Conflict before the periphery does. Eventually, in most civilizations the rate of expansion begins to decline everywhere.

As you can see Quigley seems to be more obsessed with the geopolitics of evolution of civilizations, than the sociology of it. In Tragedy and Hope, Quigley does go on to describe a certain secret society with shared values as having influenced recent world history.

So upto this point it seems like, for civilizational change we need a core leadership (or a leader) with shared values in the peripheries of a society which can offer stronger social cohesion (honor, loyalty etc) which the leadership will harness to create civilizational change.

Now let us add Rene Girard and George Friedman into this mixture.

Girard model

Rene Girard was a French historian who made popular the Scapegoat mechanism. It can be summarized as such:

  1. all of our desires are borrowed from other people. e.g. Steve Jobs learned to desire well-built products from his step-dad.
  2. all conflict originates from imitation of  desire in an environment with scarcity (e.g. there was only one Helen of Troy, so kings fight for her).
  3. sometimes the conflict and violence reach such high levels that it can threaten tribal cohesion (Khaldun’s Asabiyyah)
  4. it is at this point that the scapegoat mechanism is triggered: This is the point where one person is singled out as the cause of the trouble and is expelled or killed by the group. This person is the scapegoat. Social order is restored as people are contented that they have solved the cause of their problems by removing the scapegoated individual, and the cycle begins again. The keyword here is “content”. Scapegoating serves as a psychological relief for a group of people.
    1. Girard contends that this is what happened in the narrative of Jesus of Nazareth, the central figure in Christianity. The difference between the scapegoating of Jesus and others, Girard believes, is that in the resurrection of Jesus from the dead, he is shown to be an innocent victim; humanity is thus made aware of its violent tendencies and the cycle is broken. Thus, Girard’s work is significant as a reconstruction of the Christus Victor atonement theory.
  5. the scapegoat mechanism is the origin of sacrifice and the foundation of human culture, and religion was necessary for human evolution to control the violence that can come from the conflict that arise from desire, and that the Bible reveals these ideas and denounces the scapegoat mechanism. Girard claims sympathy for scapegoats gave rise to the rule of law and sympathy for the underdog in western society. This could be argued to be the basis of egalitarian natural rights-based societies in the west in recent history.

As you can see Rene Girard seems to be obsessed with the sociology of evolution of civilizations. And he places the scapegoating mechanism as a central player in the evolution, and one sacrifice in particular as the source of order in one civilization i.e. the west.

Friedman Model

George Friedman is a geopolitical analyst who founded the private intelligence agency STRATFOR. He covers recent demographic changes as a powerful source of civilizational change:

First, let’s face the fact that people like to have sex, and sex without birth control makes babies—and there was no birth control at the time (he means pre-industrial times). But people didn’t mind having a lot of children because children had become the basis of wealth. In an agricultural society, every pair of hands produces wealth; you don’t have to be able to read or program computers to weed, seed, or harvest. Children were also the basis for retirement, if someone lived long enough to have an old age. There was no Social Security, but you counted on your children to take care of you. Part of this was custom, but part of it was rational economic thinking. A fa­ther owned land or had the right to farm it. His child needed to have access to the land to live, so the father could dictate policy.

As children brought families prosperity and retirement income, the ma­jor responsibility of women was to produce as many children as possible. If women had children, and if they both survived childbirth, the family as a whole was better off. This was a matter of luck, but it was a chance worth taking from the standpoint of both families and the men who dominated them. Between lust and greed, there was little reason not to bring more chil­dren into the world.

Habits are hard to change. When families began moving into cities en masse, children were still valuable assets. Parents could send them to work in primitive factories at the age of six and collect their pay. In early indus­trial society factory workers didn’t need many more skills than farm laborers did. But as factories became more complex, they had less use for six-year­ olds. Soon they needed somewhat educated workers. Later they needed managers with MBAs.

As the sophistication of industry advanced, the economic value of chil­dren declined. In order to continue being economically useful, children had to go to school to learn. Rather than adding to family income, they con­sumed family income. Children had to be clothed, fed, and sheltered, and over time the amount of education they needed increased dramatically, un­til today many “children” go to school until their mid-twenties and still have not earned a dime. According to the United Nations, the average number of years of schooling in the leading twenty-five countries in the world ranges from fifteen to seventeen.

The tendency to have as many babies as possible continued into the late nineteenth and early twentieth centuries. Many of our grandparents or great-grandparents come from families that had ten children. A couple of generations before, you’d be lucky if three out of ten children survived. Now they were almost all surviving. However, in the economy of 1900, they could all head out and find work by the time they reached puberty. And that’s what most of them did.

Ten children in eighteenth-century France might have been a godsend. Ten children in late-nineteenth-century France might have been a burden. Ten children in late-twentieth-century France would be a catastrophe. It took a while for reality to sink in, but eventually it became clear that most children wouldn’t die and that children were extremely expensive to raise. Therefore, people started having a lot fewer children, and had those children more for the pleasure of having them than for economic benefits. Medical advances such as birth control helped achieve this, but the sheer cost of having and raising children drove the decline in birthrates. Children went from being producers of wealth to the most conspicuous form of consumption. Parents began satisfying their need for nurturing with one child, rather than ten.

Now let’s consider life expectancy. After all, the longer people live, the more people there will be at any given time. Life expectancy surged at the same time that infant mortality declined. In 1800, estimated life expectancy in Europe and the United States was about forty years. In 2000 it was close to eighty years. Life expectancy has, in effect, doubled over the last two hun­ dred years.

Continued growth in life expectancy is probable, but very few people anticipate another doubling. In the advanced industrial world, the UN projects a growth from seventy-six years in 2000 to eighty-two years in 2050. In the poorest countries it will increase from fifty-one to sixty-six. While this is growth, it is not geometric growth and it, too, is tapering off. This will also help reduce population growth.

The reduction process that took place decades ago in the advanced in­dustrial world is now under way in the least developed countries. Having ten children in São Paolo is the surest path to economic suicide. It may take several generations to break the habit, but it will be broken. And it won’t re­turn while the process of educating a child for the modern workforce con­tinues to become longer and costlier. Between declining birthrates and slowing increases in life expectancy, population growth has to end.

What does all this have to do with international power in the twenty-first century? The population bust affects all nations, as we will see in later chap­ters. But it also affects the life cycles of people within these nations. Lower populations affect everything from the number of troops that can fight in a war to how many people there are in the workforce to internal political conflicts. The process we are talking about will affect more than just the number of people in a country. It will change how those people live, and therefore how those countries behave.

Let’s start with three core facts. Life expectancy is moving toward a high of eighty years in the advanced industrial world; the number of children women have is declining; and it takes longer and longer to become edu­cated. A college education is now considered the minimum for social and economic success in advanced countries. Most people graduate from college at twenty-two. Add in law or graduate school, and people are not entering the workforce until their mid-twenties. Not everyone follows this pattern, of course, but a sizable portion of the population does and that portion in­cludes most of those who will be part of the political and economic leader­ship of these countries.

As a result, marriage patterns have shifted dramatically. People are put­ting off marriage longer and are having children even later. Let’s consider the effect on women. Two hundred years ago, women started having chil­dren in their early teens. Women continued having children, nurturing them, and frequently burying them until they themselves died. This was necessary for the family’s well-being and that of society. Having and raising children was what women did for most of their lives.

In the twenty-first century this whole pattern changes. Assuming that a woman reaches puberty at age thirteen and enters menopause at age fifty, she will live twice as long as her ancestors and will for over half her life be in­capable of reproduction. Let’s assume a woman has two children. She will spend eighteen months being pregnant, which is roughly 2 percent of her life. Now assume a fairly common pattern, which is that the woman will have these two children three years apart, that each child enters school at the age of five, and that the woman returns to work outside the home when the oldest starts school.

The total time the woman is engaged in reproduction and full-time nur­turing is eight years of her life. Given a life expectancy of eighty years, the amount of time exclusively devoted to having and raising children will be reduced to an astounding 10 percent of her life. Childbearing is reduced from a woman’s primary activity to one activity among many. Add to this analysis the fact that many women have only one child, and that many use day care and other mass nurturing facilities for their children well before the age of five, and the entire structure of a woman’s life is transformed.

We can see the demographic roots of feminism right here. Since women spend less of their time having and nurturing children, they are much less dependent on men than even fifty years ago. For a woman to reproduce without a husband would have created economic disaster for her in the past. This is no longer the case, particularly for better-educated women. Marriage is no longer imposed by economic necessity.

This brings us to a place where marriages are not held together by need as much as by love. The problem with love is that it can be fickle. It comes and goes. If people stay married only for emotional reasons, there will in­evitably be more divorce. The decline of economic necessity removes a pow­erful stabilizing force in marriage. Love may endure, and frequently does, but by itself it is less powerful than when linked to economic necessity.

Marriages used to be guaranteed “till death do us part.” In the past, that parting was early and frequent. There were a great many fifty-year marriages during the transition period when people were having ten surviving children. But prior to that, marriages ended early through death, and the sur­vivor remarried or faced economic ruin. Europe practiced what we might call serial polygamy, in which widowers (usually, since women tended to die in childbirth) remarried numerous times throughout their lives. In the late nineteenth and early twentieth centuries, habit kept marriages together for extraordinarily long periods of time. A new pattern emerged in the later twentieth century, however, in which serial polygamy reasserted itself, but this time the trend was being driven by divorce rather than death.

Let’s add another pattern to this. Whereas many marriages used to take place when one or both partners were in their early teens, people are now marrying in their late twenties and early thirties. It was typical for men and women to remain sexually inactive until marriage at age fourteen, but today it is, shall we say, unrealistic to expect someone marrying at age thirty to re­ main a virgin. People would be living seventeen years after puberty without sexual activity. That’s not going to happen.

There is now a period built into life patterns where people are going to be sexually active but not yet able to support themselves financially. There is also a period in which they can support themselves and are sexually active, but choose not to reproduce. The entire pattern of traditional life is collaps­ing, and no clear alternative patterns are emerging yet. Cohabitation used to be linked to formal, legal marriage, but the two are now completely decou­pled. Even reproduction is being uncoupled from marriage, and perhaps even from cohabitation. Longer life, the decline in fertility rates, and the additional years of education have all contributed to the dissolution of pre­vious life and social patterns.

This trend cannot be reversed. Women are having fewer children be­ cause supporting a lot of children in industrial, urban society is economic suicide. That won’t change. The cost of raising children will not decline, nor will there be ways found to put six-year-olds to work. The rate of infant mortality is also not going to rise. So in the twenty-first century the trend toward having fewer, rather than more, children will continue.

So as you can see we are at a crucial point in history in which falling population due to technology also has a part to play along with scapegoat mechanism, and tribes in peripheries with shared values trying to overthrow society. The future evolution civilizations will likely be driven by all the forces described above.

So how will the Future look like?

I think,

  • Europeans will be Islamicized by incoming desert tribes with shared values like how Khaldun described it.
  • The Turks on the peripheries of the fallen European civilization will expand into post-war Syria and resurrect a neo-Ottoman empire like how Carroll Quigley described it.
  • The Americans will rediscover the scapegoat mechanism and forget the 2000-year-old sacrifice that purportedly brought order to the West. They will frequently resolve escalating cultural conflict by finding scapegoats to blame everything on. They have also been historically susceptible to internal disunity (they already had Civil War I), and that is supported by the Khaldun model. I pray that Civil War II isn’t fought with nukes.
  • The Japanese will (hopefully) rediscover traditional family values and will start making babies again. But they will never reach prior peak population anytime soon thanks to the effects of technology and industrialization Friedman described. But more babies will make them more xenophobic and they will probably have imperialist ambitions e.g. nukes, space weapons, etc.
  • The Indians will be aligned with the USA, and will also start doing a lot more scapegoating to resolve tribal tensions like Girard predicted. Half the Indians still work in agriculture so I do not think Friedmanian scenarios will take place in rural India, but urban India will become uber-progressive and prosecute rape allegations without evidence.
  • The Russians will continue to be economically weakened by the anglo-american-EU  establishment but will (hopefully) survive it by rebalancing sex ratios and making more babies, and expand their sphere of influence in old Soviet satellite nations.
  • The Chinese will not become as bad demographically as the Japanese are now because of their managed birth rates. They will try to steer around ideal fertility rates.
  • The Nigerians and similar African nations will experience a population boom thanks better western medicine and scientific agriculture. Not sure what will happen to unskilled labor from Nigeria.

We are not living in an ancestor simulation

People are wondering whether post humans are simulating their ancestors (us), using their high power computers. In other words people are wondering: Can in a base world like our universe there exist a simulation of the universe itself?

Consider these 3 facts:

  1. Type III civilizations do not exist because galaxies which had most of their energy used up for some artificial purpose will appear as a type of thermodynamic black-box in our surveys of the galaxies and There is a paper which looked for such black boxes and they did not find any galactic black-boxes in the observable universe. So it appears no civilization can reach Type III level of energy consumption.
  2. There are thermodynamic limits on energy consumption of computation (see Landauer’s principle) which says At 20 °C (room temperature, or 293.15 K), the Landauer limit represents an energy of approximately 0.0172 eV, or 2.75 zJ for a single bit flip. In 2014 physical experiments tested Landauer’s principle and confirmed its predictions.
  3. Simulation of an entire universe will take more energy than what is available in a galaxy because we need to simulate 10^80 fundamental particles which is the generally accepted number of all particles in the universe. Simulating a single iron atom in a lesser than perfect manner requires you to manipulate 10^78 numbers.

Since Type III civilizations do not exist we can safely say there is not enough energy in a sub-galactic structure (e.g. a few stars) to conduct a simulation of the entire universe within it. Similar arguments can apply to all universes that are purported to be simulating itself.

Appealing to the unobserved to counter my arguments e.g. breaking Landauer’s limit, or possibility of unobserved Type III civilizations is as of now magical thinking, and I will treat it with skepticism.